Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name inplace_column_scale

Using Python 2.7 with scikit-learn 0.14 package. It runs well on some examples from the user guild expect the Linear Models.

Traceback (most recent call last):
File "E:\P\plot_ols.py", line 28, in <module>
from sklearn import datasets, linear_model
File "C:\Python27\lib\site-packages\sklearn\linear_model\__init__.py", line 12, in    <module>
from .base import LinearRegression
File "C:\Python27\lib\site-packages\sklearn\linear_model\base.py", line 29, in <module>
from ..utils.sparsefuncs import mean_variance_axis0, inplace_column_scale
ImportError: cannot import name inplace_column_scale

Thank you~

like image 443
user3479153 Avatar asked Mar 30 '14 21:03

user3479153


2 Answers

I was able to fix this by going to my python folder and deleting the file:

python27\Lib\site-packages\sklearn\utils\sparsefuncs.pyd

My guess is that the problem was:

  1. An older version of scikit-learn implemented sparsefuncs as a windows DLL
  2. The current version implements it as a python file
  3. If you install a new version on top of an old version it does not delete the old DLL
  4. When you try to import, Python uses the pyd in preference to the py implementation
  5. But the old implementation did not include this function

This suggests that there might be bigger problems caused by installing a new version and it might be wise to delete the whole sklearn directory before reinstalling the new version.

like image 104
Peter de Rivaz Avatar answered Oct 16 '22 20:10

Peter de Rivaz


I encountered the same issue in Mac Os.

I solved it by deleting the file manually:

rm /usr/local/lib/python2.7/site-packages/sklearn/utils/sparsefuncs.so

like image 18
Steven Avatar answered Oct 16 '22 20:10

Steven