-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluation.py
More file actions
43 lines (35 loc) · 1.13 KB
/
Copy pathevaluation.py
File metadata and controls
43 lines (35 loc) · 1.13 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
import pickle
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.preprocessing import MinMaxScaler
df = pickle.load(open("finaldataset", "rb"))
x = np.arange(0,1924)
df.set_index(x, inplace=True)
df2=pd.DataFrame()
row_prev=0
dataframes=[]
for row in range(len(df['class labels'])-1):
if df['class labels'][row] != df['class labels'][row+1]:
df2=df.loc[row_prev+1:row, :]
row_prev=row
dataframes.append(df2)
z = []
for frame in dataframes:
if int(frame.iloc[0,[6]].values) == 1:
z.append(frame)
framz = []
for i in range(len(z)):
framz.append(z[i])
frame = pd.concat(framz)
X = frame.iloc[:,[0,1,2,3,4,5]].values
y = frame.iloc[:,[7]].values
scaler = MinMaxScaler()
X_train_scaled = scaler.fit_transform(X)
# we must apply the scaling to the test set that we computed for the training set
knn = KNeighborsClassifier(n_neighbors = 7)
knn.fit(X, y)
print('Accuracy of K-NN classifier on training set: {:.2f}'
.format(knn.score(X, y)))