[Python] Can't import from sklearn.linear_model import LinearRegression

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have been using iPython notebook to use sklearn for a few months now with no problem and suddenly I can't get the command:

    from sklearn.linear_model import LinearRegression


    to work. I get the error:

    ---------------------------------------------------------------------------
    ImportError Traceback (most recent call last)
    <ipython-input-45-9436dcd63a89> in <module>()
    ----> 1 from sklearn.linear_model import LinearRegression

    /Users/michaelreinhard/anaconda/lib/python2.7/site-packages/sklearn/linear_model/__init__.py in <module>()
    15 from .least_angle import (Lars, LassoLars, lars_path, LarsCV, LassoLarsCV,
    16 LassoLarsIC)
    ---> 17 from .coordinate_descent import (Lasso, ElasticNet, LassoCV, ElasticNetCV,
    18 lasso_path, enet_path, MultiTaskLasso,
    19 MultiTaskElasticNet, MultiTaskElasticNetCV,

    /Users/michaelreinhard/anaconda/lib/python2.7/site-packages/sklearn/linear_model/coordinate_descent.py in <module>()
    27 from ..utils import ConvergenceWarning
    28
    ---> 29 from . import cd_fast
    30
    31

    ImportError: cannot import name cd_fast


    I have tried a lot of different things suggested on the internet, uninstalling and reinstalling Anaconda, etc., but all I have managed to do is to get the error message to change.

    The interesting thing is that the command:

    from sklearn.datasets import load_iris
    iris = load_iris()


    Worked fine.

    Any ideas on what my next step should be or what the problem is?

    Continue reading...

Compartilhe esta Página