SVM Focus on Best Parameters with GridSearchCV

Importing Modules


In [ ]:
from sklearn import svm
from sklearn.model_selection import GridSearchCV

Run Variables Setup If Necessary


In [ ]:
if 'features_train' not in locals() or globals():
    %run ../dev/environment_setup2.ipynb

Load SVM Classifier with C Parameter: Low Value


In [ ]:
parameters = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4],
                     'C': [1, 10, 100, 1000]},
                    {'kernel': ['linear'], 'C': [1, 10, 100, 1000]}]
svr = svm.SVC() 
clf = GridSearchCV(svr, parameters)

Train and Predict


In [ ]:
grid_train_predict_fulldataset("SVM with GridSearchCV and FULL DATASET...")
sorted(clf.cv_results_.keys())
param = "Best Param: " +  str(clf.best_params_)
print (param)
score = "Best Avarage Score: " + str(clf.best_score_)
print (score)