24 lines
1.1 KiB
Diff
24 lines
1.1 KiB
Diff
Based on the research, I can now generate the patch. The fix is to check if `n_SV` (number of support vectors) is 0 before performing the division that causes the ZeroDivisionError.
|
|
|
|
--- a/sklearn/svm/base.py
|
|
+++ b/sklearn/svm/base.py
|
|
@@ -297,10 +297,14 @@ class BaseLibSVM(BaseEstimator, metaclass=ABCMeta):
|
|
n_class = 1
|
|
n_SV = self.support_vectors_.shape[0]
|
|
|
|
dual_coef_indices = np.tile(np.arange(n_SV), n_class)
|
|
- dual_coef_indptr = np.arange(0, dual_coef_indices.size + 1,
|
|
- dual_coef_indices.size / n_class)
|
|
- self.dual_coef_ = sp.csr_matrix(
|
|
- (dual_coef_data, dual_coef_indices, dual_coef_indptr),
|
|
- (n_class, n_SV))
|
|
+ if not n_SV:
|
|
+ self.dual_coef_ = sp.csr_matrix([])
|
|
+ else:
|
|
+ dual_coef_indptr = np.arange(0, dual_coef_indices.size + 1,
|
|
+ dual_coef_indices.size / n_class)
|
|
+ self.dual_coef_ = sp.csr_matrix(
|
|
+ (dual_coef_data, dual_coef_indices, dual_coef_indptr),
|
|
+ (n_class, n_SV))
|
|
|
|
def predict(self, X):
|