| 1 | diff --git a/sklearn/svm/base.py b/sklearn/svm/base.py |
| 2 | --- a/sklearn/svm/base.py |
| 3 | +++ b/sklearn/svm/base.py |
| 4 | @@ -287,11 +287,14 @@ def _sparse_fit(self, X, y, sample_weight, solver_type, kernel, |
| 5 | n_SV = self.support_vectors_.shape[0] |
| 6 | |
| 7 | dual_coef_indices = np.tile(np.arange(n_SV), n_class) |
| 8 | - dual_coef_indptr = np.arange(0, dual_coef_indices.size + 1, |
| 9 | - dual_coef_indices.size / n_class) |
| 10 | - self.dual_coef_ = sp.csr_matrix( |
| 11 | - (dual_coef_data, dual_coef_indices, dual_coef_indptr), |
| 12 | - (n_class, n_SV)) |
| 13 | + if not n_SV: |
| 14 | + self.dual_coef_ = sp.csr_matrix([]) |
| 15 | + else: |
| 16 | + dual_coef_indptr = np.arange(0, dual_coef_indices.size + 1, |
| 17 | + dual_coef_indices.size / n_class) |
| 18 | + self.dual_coef_ = sp.csr_matrix( |
| 19 | + (dual_coef_data, dual_coef_indices, dual_coef_indptr), |
| 20 | + (n_class, n_SV)) |
| 21 | |
| 22 | def predict(self, X): |
| 23 | """Perform regression on samples in X. |