Skip to content

Instantly share code, notes, and snippets.

@HackerEarthBlog
Last active June 14, 2019 06:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HackerEarthBlog/a84a446810494d4ca0c178e864ab2391 to your computer and use it in GitHub Desktop.
Save HackerEarthBlog/a84a446810494d4ca0c178e864ab2391 to your computer and use it in GitHub Desktop.
Parameter tuning for SVM using Grid Search
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]]
@rbhatia46
Copy link

You are using too much values for each hyperparameter. The GridSearch will take forever to run even with a decent compute power.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment