-
Notifications
You must be signed in to change notification settings - Fork 6
/
svm.py
28 lines (18 loc) · 1.07 KB
/
svm.py
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
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV
def svm_train_search(X_train, y_train):
print('\nSVM parameter search is selected.')
params_grid = [{'decision_function_shape': ['ovo', 'ovr'], 'kernel': ['rbf'], 'gamma': [0.001, 0.01, 0.1, 1, 10, 100, 1000], 'C': [0.001, 0.01, 0.1, 1, 10, 100, 1000]},
{'decision_function_shape': ['ovo', 'ovr'],'kernel': ['linear'], 'C': [0.001, 0.01, 0.1, 1, 10, 100, 1000]},
{'decision_function_shape': ['ovo', 'ovr'], 'kernel': ['poly'], 'degree': [2, 3, 4], 'C': [0.001, 0.01, 0.1, 1, 10, 100, 1000]}]
svm_model = GridSearchCV(SVC(), params_grid, n_jobs = 30, cv = 2)
print('SVM Train...')
svm_model.fit(X_train, y_train)
print('SVM Train Finished.')
return svm_model.best_params_, svm_model.best_estimator_
def svm_train(X_train, y_train):
svm_model = SVC(kernel = 'rbf', gamma = 0.01, C = 100, random_state = 1)
print('\nSVM Train...')
svm_model.fit(X_train, y_train)
print('SVM Train Finished.')
return svm_model