user1663930
user1663930

Reputation: 315

sklearn and SVMs with polynomial kernel

I am using sklearn for python to perform cross validation using SVMs. I tried with the linear and rbf kernels and it all works fine. When i run it with the polynomial kernel though it never finishes. It has been running for 8 hours and still nothing. The dimensionality of the input X is (1422, 2)

def SupportVectorMachines(X,y):
     clf = svm.SVC(C=1.0, kernel='poly', degree=3, gamma=2)
     classifier = clf.fit(X,y)
     score = cross_validation.cross_val_score(classifier, X,y, cv=10, n_jobs=1).mean()
     return score

Any ideas why is that?

Thanks

Upvotes: 7

Views: 20989

Answers (2)

Andrew Lyubovsky
Andrew Lyubovsky

Reputation: 107

Try setting (max_iter = 1e5).

Something like:

    clf = svm.SVC(C=1.0, kernel='poly', degree=3, gamma=2,max_iter = 1e5)

It gives the following error, but terminates:

    /usr/local/lib/python3.6/dist-packages/sklearn/svm/_base.py:231: ConvergenceWarning: Solver terminated early (max_iter=100000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.  % self.max_iter, ConvergenceWarning)

Upvotes: 1

Sahana Ramnath
Sahana Ramnath

Reputation: 21

Try reducing C (try C= 0.001,0.01,0.1). C is the penalty parameter and as C gets bigger, the model tries to reduce the penalty, and so takes more time to train.

Or, try reducing the number of cross validation folds. Since the dataset consists of only 1422 points, try using cv=5. This will take a smaller running time.

Upvotes: 2

Related Questions