-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrain.py
More file actions
38 lines (23 loc) · 931 Bytes
/
Copy pathtrain.py
File metadata and controls
38 lines (23 loc) · 931 Bytes
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
from sklearn.svm import SVC
def test(clf, X, y):
from sklearn.metrics import classification_report
y_true, y_pred = y, clf.predict(X)
print(classification_report(y_true, y_pred))
def evaluate_params(X, y, X_test, y_test, params):
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import classification_report
clf = GridSearchCV(SVC(), params)
clf.fit(X, y)
means = clf.cv_results_['mean_test_score']
stds = clf.cv_results_['std_test_score']
for mean, std, params in zip(means, stds, clf.cv_results_['params']):
y_true, y_pred = y_test, clf.predict(X_test)
import pickle
def save_model(clf, model_name="clf.pkl"):
# save the classifier
with open(model_name, 'wb') as f:
pickle.dump(clf, f)
def load_model(model_name="clf.pkl"):
with open(model_name, 'rb') as f:
clf = pickle.load(f)
return clf