-
Notifications
You must be signed in to change notification settings - Fork 1
/
Datasets.py
584 lines (516 loc) · 18.4 KB
/
Datasets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
"""
@author: sibirbil
"""
import pandas as pd
def loan(wd):
"""
https://www.kaggle.com/datasets/devanshi23/loan-data-2007-2014
"""
df = pd.read_csv(wd+'loan_data_2007_2014_prepped.csv')
return df
def banknote(wd):
"""
1372 x 5
2 classes
https://archive.ics.uci.edu/ml/datasets/banknote+authentication
"""
df = pd.read_csv(wd+'data_banknote_authentication.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df
def ILPD(wd):
"""
583 x 10
2 classes
https://archive.ics.uci.edu/ml/datasets/ILPD+(Indian+Liver+Patient+Dataset)
"""
df = pd.read_csv(wd+'ILPD.csv',header = None)
df.iloc[:,1] = (df.iloc[:,1] == 'Female')*1
df.iloc[:,-1] = (df.iloc[:,-1] == 2) * 1
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
df.dropna(inplace=True)
return df
def ionosphere(wd):
"""
351 x 34
2 classes
https://archive.ics.uci.edu/ml/datasets/ionosphere
"""
df = pd.read_csv(wd+'ionosphere.csv', header = None)
df.iloc[:,-1] = (df.iloc[:,-1] == 'g')*1
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df
def transfusion(wd):
"""
748 x 5
2 classes
https://archive.ics.uci.edu/ml/datasets/Blood+Transfusion+Service+Center
"""
df = pd.read_csv(wd+'transfusion.csv', header = 0)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df
def liver(wd):
"""
345 x 7
2 classes
https://archive.ics.uci.edu/ml/datasets/liver+disorders
"""
df = pd.read_csv(wd+'bupa.csv', header = None)
df.iloc[:,-1] = (df.iloc[:,-1] == 2)*1
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df
def tictactoe(wd):
"""
958 x 9
2 classes
https://archive.ics.uci.edu/ml/datasets/Tic-Tac-Toe+Endgame
"""
df = pd.read_csv(wd+'tictactoe.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
# df1 = pd.get_dummies(df.iloc[:,:-1], drop_first=True)
df1 = pd.get_dummies(df.iloc[:, :-1], drop_first=False)
df1['y'] = (df['y'] == 'positive') *1
return df1
def wdbc(wd): # Two classes
"""
569 x 31
2 classes
https://datahub.io/machine-learning/wdbc
"""
df = pd.read_csv(wd+'wdbc.csv', header = None, index_col = 0)
df.columns = ['y'] + ['X_' + str(i) for i in range(len(df.columns)-1)]
y = (df['y'] == 'M')*1
df.drop('y', axis=1, inplace = True)
df['y'] = y
return df
def wdbc_original(wd):
"""
699 x 10
2 classes
https://networkrepository.com/breast-cancer-wisconsin-wdbc.php
"""
df = pd.read_csv(wd+'wdbc_original.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
y = (df['y'] == 4)*1
df.drop('y', axis=1, inplace = True)
df['y'] = y
return df
def mammography(wd):
"""
11183 x 6
2 classes - Imbalanced
https://www.openml.org/search?type=data&sort=runs&id=310&status=active
"""
import pandas as pd
df = pd.read_csv(wd+'mammography.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df
def diabetes_pima(wd):
"""
768 x 8
2 classes - Imbalanced
https://www.kaggle.com/datasets/uciml/pima-indians-diabetes-database
"""
import pandas as pd
df = pd.read_csv(wd+'diabetes_pima.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df
def oilspill(wd):
"""
937 x 49
2 classes - Imbalanced
https://www.kaggle.com/datasets/ashrafkhan94/oil-spill
"""
import pandas as pd
df = pd.read_csv(wd+'oilspill.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
df = df.drop(df.columns[[0]], axis = 1)
return df
def phoneme(wd):
"""
5427 x 6
2 classes - Imbalanced
https://datahub.io/machine-learning/phoneme
"""
import pandas as pd
df = pd.read_csv(wd+'phoneme.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df
def seeds(wd):
"""
210 x 7
3 classes
https://archive.ics.uci.edu/ml/datasets/seeds
"""
df = pd.read_csv(wd+'seeds.csv', header = None, sep = '\t', engine = 'python')
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df
def wine(wd):
"""
178 x 13
3 classes
https://archive.ics.uci.edu/ml/datasets/wine
"""
df = pd.read_csv(wd+'wine.csv', header = None)
df.columns = ['y'] + ['X_' + str(i) for i in range(len(df.columns)-1)]
y = df['y']
df.drop('y', axis = 1, inplace = True)
df['y'] = y
return df
def glass(wd):
"""
214 x 10
6 classes - Imbalanced
https://archive.ics.uci.edu/ml/datasets/glass+identification
"""
df = pd.read_csv(wd+'glass.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
df['y'] -= 1
return df
def ecoli(wd):
"""
336 x 8
8 classes - Imbalanced
https://archive.ics.uci.edu/ml/datasets/ecoli
"""
df = pd.read_csv(wd+'ecoli.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df
def mushroom(wd):
"""
8214 x 24
2 classes
https://archive.ics.uci.edu/ml/datasets/mushroom
"""
import pandas as pd
df = pd.read_csv(wd+'agaricus-lepiota.csv', header = None)
df.columns = ['y'] + ['X_' + str(i) for i in range(len(df.columns)-1)]
# df1 = pd.get_dummies(df.iloc[:,1:], drop_first=True)
df1 = pd.get_dummies(df.iloc[:, 1:], drop_first=False)
df1['y'] = (df['y'] == 'e') * 1
return df1
def FICO(wd):
"""
9871 x
2 classes
"""
df = pd.read_csv(wd+'FICO_v1.csv', header = None)
df.columns = ['y'] + ['X_' + str(i) for i in range(len(df.columns)-1)]
y = df['y']
df.drop('y', axis = 1, inplace = True)
df['y'] = y
return df
def bank_mkt(wd):
"""
45211 x 17
2 classes
https://archive.ics.uci.edu/ml/datasets/bank+marketing
"""
df = pd.read_csv(wd + 'bank_mkt.csv', header=None)
y = df.iloc[:, -1]
df.drop(16, inplace=True, axis=1)
cols_to_encode = [1, 2, 3, 4, 6, 7, 8, 10, 15]
# df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=True)
df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=False)
df.columns = ['X_' + str(i) for i in range(len(df.columns))]
df['y'] = (y == 'yes') * 1
return df
def hearts(wd):
"""
303 x 75
2 classes
https://archive.ics.uci.edu/ml/datasets/heart+disease
"""
df = pd.read_csv(wd + 'hearts.csv', header=None)
cols_to_encode = [1, 2, 5, 6, 8, 10, 11, 12]
# cols_to_encode = [2, 6, 10, 11, 12]
# df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=True)
df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=False)
df.columns = ['X_' + str(i) for i in range(len(df.columns) - 1)] + ['y']
return df
def musk(wd):
"""
6589 x 168
2 classes
https://archive.ics.uci.edu/ml/datasets/Musk+(Version+2)
"""
df = pd.read_csv(wd+'musk.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df
def magic(wd): # Two classes
"""
19020 x 11
2 classes
https://archive.ics.uci.edu/ml/datasets/magic+gamma+telescope
"""
import pandas as pd
df = pd.read_csv(wd+'magic.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
df['y'] = (df['y'] == 'g')*1
return df
# Fairness Datasets
def student(wd): # Five classes and two groups, sensitive attribute in the first column
"""
649 x 33
The sensitive attribute sex is to be put as the first column.
https://archive.ics.uci.edu/ml/datasets/student+performance
"""
df = pd.read_csv(wd + 'student.csv', header=None, sep='\;', engine='python')
df.columns = ['X_' + str(i) for i in range(len(df.columns) - 1)] + ['y']
print('Size data set:', len(df['y']))
address = df['X_3']
df = df.drop(columns=['X_3'])
df.insert(loc=0, column='X_3', value=address)
cols_to_encode=list(df.columns)
cols_to_encode.remove('X_3') # sensitive attribute in 1st column
cols_to_encode.remove('X_29')
cols_to_encode.remove('y')
df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=False)
return df
def student_old(wd): # Five classes and two groups, sensitive attribute in the first column
"""
649 x 33
The sensitive attribute sex is to be put as the first column.
https://archive.ics.uci.edu/ml/datasets/student+performance
"""
df = pd.read_csv(wd + 'student.csv', header=1, sep='\;', engine='python')
df.columns = ['X_' + str(i) for i in range(len(df.columns) - 1)] + ['y']
print('Size data set:', len(df['y']))
address = df['X_3']
df = df.drop(columns=['X_3'])
df.insert(loc=0, column='X_3', value=address)
return df
def adult(wd): # Two classes
"""
48842 x 14
The sensitive attribute sex is to be put as the first column.
https://archive.ics.uci.edu/ml/datasets/adult
"""
df = pd.read_csv(wd + 'adult.csv', header=None)
y = df.iloc[:, -1]
df.drop(14, inplace=True, axis=1)
sex = df[9]
df = df.drop(columns=[9])
cols_to_encode = [1, 3, 5, 6, 7, 8, 13]
# df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=True)
df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=False)
df.insert(loc=0, column='sex', value=sex)
df['y'] = (y == ' >50K') * 1
df.columns = ['X_' + str(i) for i in range(len(df.columns) - 1)] + ['y']
# df = pd.read_csv(wd+'adult.csv', header = None)
# y = df.iloc[:,-1]
# df.drop(14,inplace=True, axis=1)
# cols_to_encode = [1,3,5,6,7,8,13]
#
# sex = df[9]
# df=df.drop(columns=[9])
# df.insert(loc=1, column='sex', value=sex)
# df = pd.get_dummies(data = df, columns= cols_to_encode, drop_first=False)
# df=df.drop(columns=[0])
# df['y'] = (y == ' >50K')*1
# print(df['sex']) #1 = male
# quit()
print('Size data set:' , len(df['y']))
return df
def compas_whitevsnonwhite(wd):
"""
2 classes
6172 x 7 after prepping
https://github.com/propublica/compas-analysis/
"""
df = pd.read_csv(wd+'compas_full_whitevsnonwhite_RUG.csv', header = 0, sep = '\;', engine = 'python')
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
print('Size data set:' , len(df['y']))
return df
def compas_fairlearn(wd):
"""
2 classes
6172 x 7 after prepping
https://github.com/propublica/compas-analysis/
"""
df = pd.read_csv(wd+'compas_FAIRLEARN.csv', header = 0, sep = '\,', engine = 'python')
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
df = pd.get_dummies(data = df, columns=['X_0'], drop_first=False)
race_column = df.pop(df.columns[-1])
df.insert(0, 'race', race_column) #0=back, 1=white
df.pop(df.columns[-1])
print('Size data set:' , len(df['y']))
return df
def compas(wd):
df = pd.read_csv(wd + 'compas.csv', sep=';')
y = df['Two_yr_Recidivism']
df.drop('Two_yr_Recidivism', axis=1, inplace=True)
df.columns = ['X_' + str(i) for i in range(len(df.columns))]
df['y'] = y
df.dropna(inplace=True)
return df
'''
def compas_(wd): #0=negative class=has recommitted, 1=positive class=has not recommitted, group 0=white, group1 = black
"""
2 classes
6172 x 7 after prepping
https://github.com/propublica/compas-analysis/
"""
df = pd.read_csv(wd+'compas_blackvswhite.csv', header = 0, sep = '\;', engine = 'python')
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
print('Size data set:' , len(df['y']))
return df
'''
def compas_fairlearnpackage(wd):
"""
2 classes
6172 x 7 after prepping
https://github.com/propublica/compas-analysis/
"""
df = pd.read_csv(wd+'compas.csv', header = None, sep = '\;', engine = 'python')
#df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
print('Size data set:' , len(df['y']))
return df
def nursery(wd):
"""
12960 x 8
5 classes
https://archive.ics.uci.edu/ml/datasets/nursery
"""
df = pd.read_csv(wd+'nursery.csv', header = None, sep = '\;', engine = 'python')
# one-hot encoding for categorical variables
cols_to_encode = [1, 2, 3, 4, 5, 7] # not for target (8) & sensitive attribute (0)
df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=False)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
print('Size data set:' , len(df['y']))
return df
def nursery_old(wd):
"""
12960 x 8
5 classes
https://archive.ics.uci.edu/ml/datasets/nursery
"""
df = pd.read_csv(wd+'nursery.csv', header = None, sep = '\;', engine = 'python')
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
print('Size data set:' , len(df['y']))
return df
def default(wd):
"""
30000 x 24
2 classes
https://archive.ics.uci.edu/ml/datasets/default+of+credit+card+clients
"""
df = pd.read_csv(wd + 'default.csv')
df.dropna(inplace=True)
cols_to_encode = ['X_2', 'X_3']
# df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=True)
df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=False)
return df
'''
def default(wd):
"""
30000 x 24
2 classes
https://archive.ics.uci.edu/ml/datasets/default+of+credit+card+clients
"""
df = pd.read_csv(wd+'default.csv', header = None, sep = '\;', engine = 'python')
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
sex = df['X_1']
df = df.drop(columns=['X_1'])
df.insert(loc=0, column='X_1', value=sex) #2=femaile, 1=male
print('Size data set:' , len(df['y'])) #1=to default payment, bad label, 0=positive label
# print(df['X_1'])
# quit()
return df
'''
def law(wd): # Five classes
"""
22387 x 5
5 classes
http://www.seaphe.org/databases.php
"""
df = pd.read_csv(wd+'law.csv', header = None, sep = '\;', engine = 'python')
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
df['X_0'] = df['X_0'].apply(lambda x: 0 if x == 0 else 1) # recode sensitive attribute into two groups only (white vs. others)
print('Size data set:' , len(df['y']))
return df
def attrition(wd):
"""
1469 x 34
2 classes
https://www.kaggle.com/datasets/pavansubhasht/ibm-hr-analytics-attrition-dataset
"""
# Dataset IBM HR analytics employee attrition and performance. 0 = positive class (no attrition), 1=negative class(attrition)
df = pd.read_csv(wd+'attrition.csv', header=0, sep = '\;', engine = 'python')
# put sensitive attribute in first column
workLifeBalance = df['WorkLifeBalance']
df = df.drop(columns=['WorkLifeBalance'])
df.insert(loc=0, column='X_0', value=workLifeBalance)
y = df['Attrition']
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
cols_to_encode = ['X_3', 'X_5', 'X_8', 'X_15', 'X_17', 'X_21', 'X_22']
df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=False)
df['y'] = (y == 'Yes') * 1
return df
def attrition_old(wd):
"""
1469 x 34
2 classes
https://www.kaggle.com/datasets/pavansubhasht/ibm-hr-analytics-attrition-dataset
"""
# Dataset IBM HR analytics employee attrition and performance. 0 = positive class (no attrition), 1=negative class(attrition)
df = pd.read_csv(wd+'attrition.csv', header=0, sep = '\;', engine = 'python')
workLifeBalance = df['WorkLifeBalance']
df = df.drop(columns=['WorkLifeBalance'])
df.insert(loc=0, column='X_0', value=workLifeBalance)
y = df['Attrition']
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
cols_to_encode = ['X_0', 'X_3', 'X_5', 'X_8', 'X_15', 'X_17', 'X_21', 'X_22']
# df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=True)
df = pd.get_dummies(data=df, columns=cols_to_encode, drop_first=False)
# df['y'] = pd.factorize(df['y'])[0]
df['y'] = (y == 'Yes') * 1
# df.columns = ['X_' + str(i) for i in range(len(df.columns) - 1)] + ['y']
return df
def recruitment(wd):
"""
215 x 12
8 classes
https://www.kaggle.com/datasets/benroshan/factors-affecting-campus-placement
"""
df = pd.read_csv(wd+'recruitment.csv', header = None, sep = '\;', engine = 'python')
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
print('Size data set:' , len(df['y']))
return df
## Large Classification
def sensorless(wd):
"""
58509 x 48
11 classes
https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass.html#Sensorless
"""
df = pd.read_csv(wd+'sensorless.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
df['y'] -= 1
return df
def skinnonskin(wd):
"""
245057 x 3
2 classes
https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html#skin_nonskin
"""
df = pd.read_csv(wd+'skinnonskin.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
df['y'] -= 1
return df
def covtype(wd):
"""
581012 x 54
7 classes
https://archive.ics.uci.edu/ml/datasets/covertype
"""
df = pd.read_csv(wd+'covtype.csv', header = None)
y = df.iloc[:,-1]-1
# First ten quantitative columns only (last one is for y)
df = df.iloc[:, 0:11]
df.columns = ['X_' + str(i) for i in range(10)] + ['y']
df['y'] = y
return df
def eicu_mortality(wd):
df = pd.read_csv(wd+'adult_data_feat_imp.csv', header = None)
df.columns = ['X_' + str(i) for i in range(len(df.columns)-1)] + ['y']
return df