Reputation: 53
I am trying to use SVC class in scikit-learn library to solve a multi-class classification problem. I am interested in one-vs-one strategy. And I want to optimize hyper-parameters (C and gamma) for each pair of classes. But I don't know how to do that in scikit-learn. How can I do that? Thank you very much.
Upvotes: 1
Views: 2730
Reputation: 2321
As mentioned by @ncfirth you can use GridSearchCV to find the best parameters based on your training set. I have used the following code in my program.
tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4, 1e-5, 1e-6, 1e-7, 1e-8],
'C': [1, 10, 100, 1000]}]
scores = ['precision', 'recall']
for score in scores:
print("# Tuning hyper-parameters for %s" % score)
print()
clf = GridSearchCV(svm.SVC(C=1), tuned_parameters, cv=5,
scoring='%s_macro' % score)
clf.fit(X, Y)
print("Best parameters set found on development set:")
print()
print(clf.best_params_)
I got the above solution from stackoverflow (don't have the link to it) and it helped me to choose the right gamma and C values in my program. My requirement was to check for 'rbf' kernel only. You can include linear, poly and other kernels and its parameters to check for your fit to your program.
Upvotes: 3