Elffuss BraidHub

kikocis/auto-code-rover public

main · 2.3 KiBRawPermalink
1IndexError thrown with LogisticRegressionCV and refit=False
2#### Description
3The following error is thrown when trying to estimate a regularization parameter via cross-validation, *without* refitting.
4
5#### Steps/Code to Reproduce
6```python
7import sys
8import sklearn
9from sklearn.linear_model import LogisticRegressionCV
10import numpy as np
11
12np.random.seed(29)
13X = np.random.normal(size=(1000, 3))
14beta = np.random.normal(size=3)
15intercept = np.random.normal(size=None)
16y = np.sign(intercept + X @ beta)
17
18LogisticRegressionCV(
19cv=5,
20solver='saga', # same error with 'liblinear'
21tol=1e-2,
22refit=False).fit(X, y)
23```
24
25
26#### Expected Results
27No error is thrown.
28
29#### Actual Results
30```
31---------------------------------------------------------------------------
32IndexError 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
50IndexError: too many indices for array
51```
52
53#### Versions
54```
55System:
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)]
57executable: /Users/tsweetser/.pyenv/versions/3.6.7/envs/jupyter/bin/python
58 machine: Darwin-18.6.0-x86_64-i386-64bit
59
60BLAS:
61 macros: NO_ATLAS_INFO=3, HAVE_CBLAS=None
62 lib_dirs:
63cblas_libs: cblas
64
65Python deps:
66 pip: 19.1.1
67setuptools: 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```