Last active
June 14, 2019 06:43
-
-
Save HackerEarthBlog/a84a446810494d4ca0c178e864ab2391 to your computer and use it in GitHub Desktop.
Parameter tuning for SVM using Grid Search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.model_selection import GridSearchCV | |
parameters = {'kernel':('linear', 'rbf'), 'C':[1,2,3,4,5,6,7,8,9,10], 'gamma': | |
[0.01,0.02,0.03,0.04,0.05,0.10,0.2,0.3,0.4,0.5]} | |
svr = svm.SVC() | |
grid = GridSearchCV(svr, parameters) | |
grid.fit(X_train, y_train) | |
predicted = grid.predict(X_test) | |
cnf_matrix = confusion_matrix(y_test, predicted) | |
print(cnf_matrix) | |
[[16 0 0] | |
[ 0 13 5] | |
[ 0 3 8]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are using too much values for each hyperparameter. The GridSearch will take forever to run even with a decent compute power.