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
In machine learning, the polynomial kernel is a kernel function commonly used with support vector machines (SVMs) and other kernelized models, that represents the similarity of vectors (training samples) in a feature space over polynomials of the original variables, allowing learning of non-linear models.
Rather, a modified version of SVM, called Kernel SVM, is used. Basically, the kernel SVM projects the non-linearly separable data lower dimensions to linearly separable data in higher dimensions in such a way that data points belonging to different classes are allocated to different dimensions.
To fit an SVM with a polynomial kernel we use kernel="polynomial" , and to fit an SVM with a radial kernel we use kernel="radial" . In the former case we also use the degree argument to specify a degree for the polynomial kernel, and in the latter case we use gamma to specify a value of γ for the radial basis kernel.
As discussed earlier, SVM is used for both classification and regression problems. Scikit-learn's method of Support Vector Classification (SVC) can be extended to solve regression problems as well. That extended method is called Support Vector Regression (SVR).
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With