Repository navigation
Expand file tree
/
Copy pathload.py
More file actions
161 lines (146 loc) · 6.26 KB
/
Copy pathload.py
File metadata and controls
161 lines (146 loc) · 6.26 KB
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
# -*- coding: utf-8 -*-
"""load.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1njbMoe5-jIrxCVJqMA4Mb2qmAFWtmf0O
"""
import pandas as pd
import numpy as np
def load(dataset_name):
# Rule used for renaming class labels: (Class Label - Numeric Code)
# _______________________________________________________________________________
# Iris Setosa - 0
# Iris Versicolor - 1
# Iris Virginica - 2
# _______________________________________________________________________________
if dataset_name == "iris":
csv_url = "datasets/iris/iris.data"
iris = pd.read_csv(csv_url, header=None)
X = iris.iloc[:, :-1]
Y = iris.iloc[:, -1]
# Map string labels to numeric codes
class_mapping = {
'Iris-setosa': 0,
'Iris-versicolor': 1,
'Iris-virginica': 2
}
Y = Y.map(class_mapping)
return X, Y
# ____________________________________________________________
# Rule used for renaming class labels: (Class Label - Numeric Code)
# _______________________________________________________________________________
# b (Bad) - 0
# g (Good) - 1
# _______________________________________________________________________________
elif dataset_name == "ionosphere":
csv_url = "datasets/ionosphere/ionosphere.data"
ionosphere = pd.read_csv(csv_url, sep=",", header=None)
X = ionosphere.iloc[:, :-1]
# pd.set_option('future.no_silent_downcasting', True)
# Map string labels to numeric codes
class_mapping_ionosphere = {
'b': 0,
'g': 1,
}
Y = ionosphere.iloc[:, -1].map(class_mapping_ionosphere)
return X, Y
# _______________________________________________________________________________
# Rule used for renaming class labels: (Class Label - Numeric Code)
# _______________________________________________________________________________
# M (Malignant) - 0
# B (Benign) - 1
# _______________________________________________________________________________
elif dataset_name == "breastcancerwisconsin":
csv_url = "datasets/breastcancerwisconsin/wdbc.data"
breastcancer = pd.read_csv(csv_url, sep=",", header=None)
X = breastcancer.iloc[:, 2:]
# Map string labels to numeric codes
class_mapping_cancer = {
'M': 0,
'B': 1,
}
Y = breastcancer.iloc[:, 1].map(class_mapping_cancer)
return X, Y
# _______________________________________________________________________________
# Rule used for renaming class labels: (Class Label - Numeric Code)
# _______________________________________________________________________________
# 1.0 - 0
# 2.0 - 1
# 3.0 - 2
# _______________________________________________________________________________
elif dataset_name == "wine":
# 13 features and 3 label
csv_url = "datasets/wine/wine.data"
wine = pd.read_csv(csv_url, sep=",", header=None)
#reading data and labels from the dataset
X = wine.iloc[:, 1:] # Features are in columns 1 through end
Y = wine.iloc[:, 0] # Labels are in column 0
# Map labels to numeric codes
class_mapping_wine = {
1: 0,
2: 1,
3: 2
}
Y = Y.map(class_mapping_wine)
return X,Y
# Rule used for renaming class labels: (Class Label - Numeric Code)
# _______________________________________________________________________________
# 1.0 - 0
# 2.0 - 1
# _______________________________________________________________________________
elif dataset_name == "appendicitis":
# 7 features and 2 label
csv_url = "datasets/appendicitis/appendicitis.data"
appendicitis = pd.read_csv(csv_url, sep=",", header=None)
#reading data and labels from the dataset
X = appendicitis.iloc[:, :-1] # Features are in columns 0 through second last
Y = appendicitis.iloc[:, -1] # Labels are in column last column
# Map labels to numeric codes
class_mapping_appendicitis = {
1: 0,
2: 1,
}
Y = Y.map(class_mapping_appendicitis)
return X,Y
# Rule used for renaming class labels: (Class Label - Numeric Code)
# _______________________________________________________________________________
# 0.0 - 0
# 1.0 - 1
# _______________________________________________________________________________
elif dataset_name == "diabetespimaindian":
# 8 features and 2 label
csv_url = "datasets/diabetespimaindian/diabetes_pima_indian.data"
diabetespimaindian = pd.read_csv(csv_url, sep=",", header=None)
#reading data and labels from the dataset
X = diabetespimaindian.iloc[:, :-1] # Features are in columns 0 through second last
Y = diabetespimaindian.iloc[:, -1] # Labels are in column last column
# Map labels to numeric codes
class_mapping_diabetespimaindian = {
0.0: 0,
1.0: 1,
}
Y = Y.map(class_mapping_diabetespimaindian)
return X,Y
# Rule used for renaming class labels: (Class Label - Numeric Code)
# _______________________________________________________________________________
# 'R' (Rock) - 0
# 'M' (Mine) - 1
# _______________________________________________________________________________
elif dataset_name == "sonar":
# Datasource:- https://archive.ics.uci.edu/dataset/151/connectionist+bench+sonar+mines+vs+rocks
# 60 features and 2 label
csv_url = "datasets/sonar/sonar.data"
sonar = pd.read_csv(csv_url, sep=",", header=None)
#reading data and labels from the dataset
X = sonar.iloc[:, :-1] # Features are in columns 0 through second last
Y = sonar.iloc[:, -1] # Labels are in column last column
# Map labels to numeric codes
class_mapping_sonar = {
'R': 0,
'M': 1,
}
Y = Y.map(class_mapping_sonar)
return X,Y
else:
print("Dataset not found.")
return None, None