| 1 | diff --git a/sklearn/linear_model/logistic.py b/sklearn/linear_model/logistic.py |
| 2 | --- a/sklearn/linear_model/logistic.py |
| 3 | +++ b/sklearn/linear_model/logistic.py |
| 4 | @@ -2170,7 +2170,7 @@ def fit(self, X, y, sample_weight=None): |
| 5 | # Take the best scores across every fold and the average of |
| 6 | # all coefficients corresponding to the best scores. |
| 7 | best_indices = np.argmax(scores, axis=1) |
| 8 | - if self.multi_class == 'ovr': |
| 9 | + if multi_class == 'ovr': |
| 10 | w = np.mean([coefs_paths[i, best_indices[i], :] |
| 11 | for i in range(len(folds))], axis=0) |
| 12 | else: |
| 13 | @@ -2180,8 +2180,11 @@ def fit(self, X, y, sample_weight=None): |
| 14 | best_indices_C = best_indices % len(self.Cs_) |
| 15 | self.C_.append(np.mean(self.Cs_[best_indices_C])) |
| 16 | |
| 17 | - best_indices_l1 = best_indices // len(self.Cs_) |
| 18 | - self.l1_ratio_.append(np.mean(l1_ratios_[best_indices_l1])) |
| 19 | + if self.penalty == 'elasticnet': |
| 20 | + best_indices_l1 = best_indices // len(self.Cs_) |
| 21 | + self.l1_ratio_.append(np.mean(l1_ratios_[best_indices_l1])) |
| 22 | + else: |
| 23 | + self.l1_ratio_.append(None) |
| 24 | |
| 25 | if multi_class == 'multinomial': |
| 26 | self.C_ = np.tile(self.C_, n_classes) |