语句
from sklearn.linear_model import RandomizedLogisticRegression
报错
ImportError: cannot import name 'RandomizedLogisticRegression' from 'sklearn.linear_model' (D:\Users\urse\Anaconda3\lib\site-packages\sklearn\linear_model\__init__.py)
解决办法
首先尝试了网络上的pip uninstall sklearn,再pip install sklearn,依然报同样的错误,而以前anaconda安装后不会报该错误,怀疑是sklearn版本跟新导致的错误。
查得sklearn(版本0.21.3)的linear_model文件夹下面已经没有randomized_l1.py文件,而RandomizedLogisticRegression就在该文件内。RandomizedLogisticRegression已经被移出sklearn包,移到了 scikit-learn-contrib/stability-selection中(安装方法详见链接)。
提取的stability-selection安装过程(后两步需要cd到对应文件的路径下面运行):
- git clone https://github.com/scikit-learn-contrib/stability-selection.git
- pip install -r requirements.txt
- python setup.py install
安装后运行 from stability_selection.randomized_lasso import RandomizedLogisticRegression,import正常。