Cannot import sklearn.model_selection in scikit-learn

后端 未结 1 1812
野性不改
野性不改 2021-01-11 21:45

I am trying to import sklearn.model_selection. I have tried to reinstall scikit-learn and anaconda, still not working. Here is the error msg I got:

         


        
相关标签:
1条回答
  • 2021-01-11 22:23

    Check your scikit-learn version;

    import sklearn
    print(sklearn.__version__)
    

    sklearn.model_selection is available for version 0.18.1.

    What you need to import depends on what you require. For instance, in version 0.18.1, GridSearchCV can be imported as

    from sklearn.model_selection import GridSearchCV
    

    Whereas in version 0.17.1, the same can be imported as

    from sklearn.grid_search import GridSearchCV
    

    If you find anything in the new scikit documentation that doesn't work for you in your system, then search the document for the current version you are using. The import path might be different but the overall functionality ought to be the same.

    If you don't have any previous projects or code that requires the older version, the better option would be to update your scikit-learn package. As you stated that you use Anaconda, the following post would be useful:

    How to upgrade scikit-learn package in anaconda

    0 讨论(0)
提交回复
热议问题