Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[MRG] Fix ZeroDivisionError when using sparse data in SVM in case where support_vectors_ is empty #14894
What does this implement/fix? Explain your changes.
When model.support_vectors_ is an empty sparse matrix, to calculate model.dual_coef_, we use
which results in ZeroDivisionError.
Any other comments?
@danna-naser thanks for reporting it and the fix. But it may be the case that there's another underlying issue we need to solve.
@agramfort could you please have a look at this one? The issue is that sometimes you may get a solution from the SVR with 0 support vectors, and the output is just the intercept. The question is, do we want to raise a warning or even an error? Also, this example is very curious in the sense that the intercept is not the mean of all the data points.
import numpy as np from scipy import sparse from sklearn import svm x_train = np.array([[0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) y_train = np.array([0.04, 0.04, 0.10, 0.16]) model = svm.SVR(kernel='linear') model.fit(x_train, y_train)