forked from VeronicaPistolesi/MachineLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_extraction_monks.py
More file actions
190 lines (121 loc) · 4.32 KB
/
set_extraction_monks.py
File metadata and controls
190 lines (121 loc) · 4.32 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
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
# -*- coding: utf-8 -*-
"""set_extraction_monks.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1c4BJyGQ_G3V5wZ4dKvTGOutN2fzMWgNc
# Libraries
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import OneHotEncoder
from sklearn.utils import shuffle
"""# Data Loading monks-1
"""
cols = ['class', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'Id']
train_m1 = pd.read_csv("data/monks-1.train", sep = " ", skipinitialspace=True, names = cols)
test_m1 = pd.read_csv("data/monks-1.test", sep = " ", skipinitialspace=True, names = cols)
train_m1.head(3)
test_m1.head(3)
train_m1.set_index("Id", inplace=True)
test_m1.set_index("Id", inplace=True)
train_m1.head(3)
test_m1.head(3)
train_m1.shape
test_m1.shape
train_m1.info()
test_m1.info()
x_train_m1 = train_m1.iloc[:, 1:7].values
y_train_m1 = train_m1.iloc[:, 0].values
x_test_m1 = test_m1.iloc[:, 1:7].values
y_test_m1 = test_m1.iloc[:, 0].values
print("Shapes before encoding:")
print("x_train_m1", x_train_m1.shape)
print("y_train_m1", y_train_m1.shape)
print("x_test_m1", x_test_m1.shape)
print("y_test_m1", y_test_m1.shape)
# Encoding
encoder = OneHotEncoder(sparse=False)
x_train_m1 = encoder.fit_transform(x_train_m1)
encoder = OneHotEncoder(sparse=False)
x_test_m1 = encoder.fit_transform(x_test_m1)
x_train_m1, y_train_m1 = shuffle(x_train_m1, y_train_m1, random_state=42)
x_test_m1, y_test_m1 = shuffle(x_test_m1, y_test_m1, random_state=42)
print("Shapes after encoding:")
print("x_train_m1", x_train_m1.shape)
print("y_train_m1", y_train_m1.shape)
print("x_test_m1", x_test_m1.shape)
print("y_test_m1", y_test_m1.shape)
"""# Data Loading monks-2
"""
cols = ['class', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'Id']
train_m2 = pd.read_csv("data/monks-2.train", sep = " ", skipinitialspace=True, names = cols)
test_m2 = pd.read_csv("data/monks-2.test", sep = " ", skipinitialspace=True, names = cols)
train_m2.head(3)
test_m2.head(3)
train_m2.set_index("Id", inplace=True)
test_m2.set_index("Id", inplace=True)
train_m2.head(3)
test_m2.head(3)
train_m2.shape
test_m2.shape
train_m2.info()
test_m2.info()
x_train_m2 = train_m2.iloc[:, 1:7].values
y_train_m2 = train_m2.iloc[:, 0].values
x_test_m2 = test_m2.iloc[:, 1:7].values
y_test_m2 = test_m2.iloc[:, 0].values
print("Shapes before encoding:")
print("x_train_m2", x_train_m2.shape)
print("y_train_m2", y_train_m2.shape)
print("x_test_m2", x_test_m2.shape)
print("y_test_m2", y_test_m2.shape)
# Encoding
encoder = OneHotEncoder(sparse=False)
x_train_m2 = encoder.fit_transform(x_train_m2)
encoder = OneHotEncoder(sparse=False)
x_test_m2 = encoder.fit_transform(x_test_m2)
x_train_m2, y_train_m2 = shuffle(x_train_m2, y_train_m2, random_state=42)
x_test_m2, y_test_m2 = shuffle(x_test_m2, y_test_m2, random_state=42)
print("Shapes after encoding:")
print("x_train_m2", x_train_m2.shape)
print("y_train_m2", y_train_m2.shape)
print("x_test_m2", x_test_m2.shape)
print("y_test_m2", y_test_m2.shape)
"""# Data Loading monks-3
"""
cols = ['class', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'Id']
train_m3 = pd.read_csv("data/monks-3.train", sep = " ", skipinitialspace=True, names = cols)
test_m3 = pd.read_csv("data/monks-3.test", sep = " ", skipinitialspace=True, names = cols)
train_m3.head(3)
test_m3.head(3)
train_m3.set_index("Id", inplace=True)
test_m3.set_index("Id", inplace=True)
train_m3.head(3)
test_m3.head(3)
train_m3.shape
test_m3.shape
train_m3.info()
test_m3.info()
x_train_m3 = train_m3.iloc[:, 1:7].values
y_train_m3 = train_m3.iloc[:, 0].values
x_test_m3 = test_m3.iloc[:, 1:7].values
y_test_m3 = test_m3.iloc[:, 0].values
print("Shapes before encoding:")
print("x_train_m3", x_train_m3.shape)
print("y_train_m3", y_train_m3.shape)
print("x_test_m3", x_test_m3.shape)
print("y_test_m3", y_test_m3.shape)
# Encoding
encoder = OneHotEncoder(sparse=False)
x_train_m3 = encoder.fit_transform(x_train_m3)
encoder = OneHotEncoder(sparse=False)
x_test_m3 = encoder.fit_transform(x_test_m3)
x_train_m3, y_train_m3 = shuffle(x_train_m3, y_train_m3, random_state=42)
x_test_m3, y_test_m3 = shuffle(x_test_m3, y_test_m3, random_state=42)
print("Shapes after encoding:")
print("x_train_m3", x_train_m3.shape)
print("y_train_m3", y_train_m3.shape)
print("x_test_m3", x_test_m3.shape)
print("y_test_m3", y_test_m3.shape)