-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
109 lines (77 loc) · 2.32 KB
/
testing.py
File metadata and controls
109 lines (77 loc) · 2.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
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.pipeline import Pipeline
from sklearn import metrics
import joblib
import pandas as pd
df = pd.read_csv("data.csv", index_col=0)
print(df.shape)
x = df.drop(["9"],axis=1)
data = df.drop_duplicates(subset = x.columns,keep='last')
print(data.shape)
x = df.drop(["9"],axis=1)
y = df.drop(x.columns,axis=1)
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.3, random_state=1)
pipe = Pipeline([
('model' ,RandomForestClassifier(max_depth=4, n_estimators=10, max_features=9 ),)
])
mod = GridSearchCV(estimator = RandomForestClassifier(),
param_grid={'max_depth' : [1,2,3,4,5,6,7,8,9,10]},
cv=3)
mod.fit(x_train,y_train)
pre = mod.predict(x_test)
print()
print()
print("RandomForestClassifier",metrics.accuracy_score(y_test,pre))
print()
print()
pipe = Pipeline([
('model' ,DecisionTreeClassifier(max_depth=4)),
])
mod = GridSearchCV(estimator = DecisionTreeClassifier(),
param_grid={'max_depth' : [1,2,3,4,5,6,7,8,9,10]},
cv=3)
mod.fit(x_train,y_train)
pre = mod.predict(x_test)
print()
print()
print("DecisionTreeClassifier",metrics.accuracy_score(y_test,pre))
print()
print()
pipe = Pipeline([
('model' ,AdaBoostClassifier()),
])
#mod = GridSearchCV(estimator = AdaBoostClassifier(), cv=3)
#mod.fit(x_train,y_train)
#pre = mod.predict(x_test)
pipe.fit(x_train,y_train)
pre = pipe.predict(x_test)
print()
print()
print("AdaBoostClassifier",metrics.accuracy_score(y_test,pre))
print()
print()
#mod = GridSearchCV(estimator = KNeighborsClassifier(),cv=3)
#mod.fit(x_train,y_train)
#pre = mod.predict(x_test)
pipe = Pipeline([
('model' ,KNeighborsClassifier()),
])
pipe.fit(x_train,y_train)
pre = pipe.predict(x_test)
print()
print()
print("KNeighborsClassifier",metrics.accuracy_score(y_test,pre))
print()
print()
pipe = joblib.load("model.joblib")
pre = pipe.predict(x_test)
print()
print()
print("from model",metrics.accuracy_score(y_test,pre))
print()
print()
#joblib.dump(pipe,"model.joblib")