| 1 | IndexError thrown with LogisticRegressionCV and refit=False |
| 2 | #### Description |
| 3 | The following error is thrown when trying to estimate a regularization parameter via cross-validation, *without* refitting. |
| 4 | |
| 5 | #### Steps/Code to Reproduce |
| 6 | ```python |
| 7 | import sys |
| 8 | import sklearn |
| 9 | from sklearn.linear_model import LogisticRegressionCV |
| 10 | import numpy as np |
| 11 | |
| 12 | np.random.seed(29) |
| 13 | X = np.random.normal(size=(1000, 3)) |
| 14 | beta = np.random.normal(size=3) |
| 15 | intercept = np.random.normal(size=None) |
| 16 | y = np.sign(intercept + X @ beta) |
| 17 | |
| 18 | LogisticRegressionCV( |
| 19 | cv=5, |
| 20 | solver='saga', # same error with 'liblinear' |
| 21 | tol=1e-2, |
| 22 | refit=False).fit(X, y) |
| 23 | ``` |
| 24 | |
| 25 | |
| 26 | #### Expected Results |
| 27 | No error is thrown. |
| 28 | |
| 29 | #### Actual Results |
| 30 | ``` |
| 31 | --------------------------------------------------------------------------- |
| 32 | IndexError Traceback (most recent call last) |
| 33 | <ipython-input-3-81609fd8d2ca> in <module> |
| 34 | ----> 1 LogisticRegressionCV(refit=False).fit(X, y) |
| 35 | |
| 36 | ~/.pyenv/versions/3.6.7/envs/jupyter/lib/python3.6/site-packages/sklearn/linear_model/logistic.py in fit(self, X, y, sample_weight) |
| 37 | 2192 else: |
| 38 | 2193 w = np.mean([coefs_paths[:, i, best_indices[i], :] |
| 39 | -> 2194 for i in range(len(folds))], axis=0) |
| 40 | 2195 |
| 41 | 2196 best_indices_C = best_indices % len(self.Cs_) |
| 42 | |
| 43 | ~/.pyenv/versions/3.6.7/envs/jupyter/lib/python3.6/site-packages/sklearn/linear_model/logistic.py in <listcomp>(.0) |
| 44 | 2192 else: |
| 45 | 2193 w = np.mean([coefs_paths[:, i, best_indices[i], :] |
| 46 | -> 2194 for i in range(len(folds))], axis=0) |
| 47 | 2195 |
| 48 | 2196 best_indices_C = best_indices % len(self.Cs_) |
| 49 | |
| 50 | IndexError: too many indices for array |
| 51 | ``` |
| 52 | |
| 53 | #### Versions |
| 54 | ``` |
| 55 | System: |
| 56 | python: 3.6.7 (default, May 13 2019, 16:14:45) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] |
| 57 | executable: /Users/tsweetser/.pyenv/versions/3.6.7/envs/jupyter/bin/python |
| 58 | machine: Darwin-18.6.0-x86_64-i386-64bit |
| 59 | |
| 60 | BLAS: |
| 61 | macros: NO_ATLAS_INFO=3, HAVE_CBLAS=None |
| 62 | lib_dirs: |
| 63 | cblas_libs: cblas |
| 64 | |
| 65 | Python deps: |
| 66 | pip: 19.1.1 |
| 67 | setuptools: 39.0.1 |
| 68 | sklearn: 0.21.2 |
| 69 | numpy: 1.15.1 |
| 70 | scipy: 1.1.0 |
| 71 | Cython: 0.29.6 |
| 72 | pandas: 0.24.2 |
| 73 | ``` |