No module name ‘sklearn.forest.ensemble’

We Are Going To Discuss About No module name ‘sklearn.ensemble.forest’. So lets Start this Python Article.

No module name ‘sklearn.ensemble.forest’

  1. How to solve No module name 'sklearn.forest.ensemble'

    sklearn.ensemble.forest was renamed to sklearn.ensemble._forest in 437ca05 on Oct 16, 2019. You need to install an older sklearn. Try version 0.21.3 released on Jul 30, 2019:
    pip install -U scikit-learn==0.21.3
    Please be warned that the authors provided wheels up to Python 3.7. For 3.8 or 3.9 you will need to compile from sources.

  2. No module name 'sklearn.forest.ensemble'

    sklearn.ensemble.forest was renamed to sklearn.ensemble._forest in 437ca05 on Oct 16, 2019. You need to install an older sklearn. Try version 0.21.3 released on Jul 30, 2019:
    pip install -U scikit-learn==0.21.3
    Please be warned that the authors provided wheels up to Python 3.7. For 3.8 or 3.9 you will need to compile from sources.

Solution 1

sklearn.ensemble.forest was renamed to sklearn.ensemble._forest in 437ca05 on Oct 16, 2019. You need to install an older sklearn. Try version 0.21.3 released on Jul 30, 2019:

pip install -U scikit-learn==0.21.3

Please be warned that the authors provided wheels up to Python 3.7. For 3.8 or 3.9 you will need to compile from sources.

Original Author phd Of This Content

Solution 2

The answer above is correct,
sklearn.ensemble.forest is renamed to sklearn.ensemble._forest

This problem persist with more libraries that depend on sklearn, therefore I want to provide an additional solution that universally for most of these packages.

In your case your library is called face_detector, but you can replace it with any library name when you encounter this issue with versioning of scikit-learn (as well as with other libraries).

  1. Locate the directory of the library:

    import face_detector
    print(face_detector.\_\_file__)
    
  2. Open the file in any text editor, in your case the name of the library file would be face_detector.py

  3. Out-comment the old import and replace with the new import.

    Comment out the import for the old versions of sklearn and add the new import statement

    # from sklearn.ensemble.forest import ForestClassifier, ForestRegressor
    from sklearn.ensemble._forest import ForestClassifier, ForestRegressor
    
  4. Safe and enjoy, you just fixed a dependency issue!
    This solution will work for most libraries and is even less work than installing a different version of sklearn. In case it does not work, you can still install and older version as suggested in the other answer.

Note: This solution can be easily modified to trace and fix dependency issues for other library dependencies than sklearn. As long as the function itself did not change in input and output parameters, fixing renaming issues is an easy way to fix broken dependencies.

Original Author Niels Zondervan Of This Content

Solution 3

maybe your model is too old. use:

pip install scikit-learn==0.22

to install the old version of sklearn.

Original Author YouLu Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment