Search code examples
python-2.7modelscikit-learnimporterror

sklearn 0.17.1: ImportError: cannot import name inplace_column_scale


My sklearn works well before, after installing and updating a couple of other packages, I cannot import any model from sklearn.

The versions:

Python 2.7.12
Anaconda 2.4.1 (x86_64)
sklearn: 0.17.1 (downgrade from 0.18) spicy: 0.18.1

Measures I've tried:

  1. restart the shell---> same error

  2. uninstall sklearn, and reinstall it (the newest version is 0.18), downgrade it to 0.17--> same error

  3. install sklearn and keep the version 0.18 -->still error

My code:

from sklearn import svm

The error

Traceback (most recent call last):

  File "<ipython-input-1-fe795c4388c4>", line 3, in <module>
    from sklearn import svm

  File "//anaconda/lib/python2.7/site-packages/sklearn/svm/__init__.py", line 13, in <module>
    from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC, \

  File "//anaconda/lib/python2.7/site-packages/sklearn/svm/classes.py", line 4, in <module>
    from .base import _fit_liblinear, BaseSVC, BaseLibSVM

  File "//anaconda/lib/python2.7/site-packages/sklearn/svm/base.py", line 11, in <module>
    from ..preprocessing import LabelEncoder

  File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/__init__.py", line 8, in <module>
    from .data import Binarizer

  File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 25, in <module>
    from ..utils.sparsefuncs import (inplace_column_scale,

ImportError: cannot import name inplace_column_scale

Besides svm, when I import tree, linear_model, the same thing happens.

from sklearn.models import linear_model

The error:

Traceback (most recent call last):

  File "<ipython-input-3-540f6792b379>", line 1, in <module>
    from sklearn.models import linear_model

ImportError: No module named models

Code:

from sklearn import tree

error: Traceback (most recent call last):

  File "<ipython-input-4-fcc6e7d2ee3e>", line 1, in <module>
    from sklearn import tree

  File "//anaconda/lib/python2.7/site-packages/sklearn/tree/__init__.py", line 6, in <module>
    from .tree import DecisionTreeClassifier

  File "//anaconda/lib/python2.7/site-packages/sklearn/tree/tree.py", line 30, in <module>
    from ..feature_selection.from_model import _LearntSelectorMixin

  File "//anaconda/lib/python2.7/site-packages/sklearn/feature_selection/__init__.py", line 7, in <module>
    from .univariate_selection import chi2

  File "//anaconda/lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.py", line 15, in <module>
    from ..preprocessing import LabelBinarizer

  File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/__init__.py", line 8, in <module>
    from .data import Binarizer

  File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 25, in <module>
    from ..utils.sparsefuncs import (inplace_column_scale,

ImportError: cannot import name inplace_column_scale

Solution

  • Try this within your terminal:

    conda install -c anaconda scikit-learn=0.18.1
    

    If it does not work go to your terminal and try:

    conda update anaconda
    

    After the update is complete, then try the first bit of code again Hopefully it works