1
from flask import Flask, render_template, request
import pickle
import numpy as np

#Load the Random Forest Classifier model

filename = 'first-innings-score-lr-model'
regressor = pickle.load(open(filename, 'rb'))

error

Traceback (most recent call last):
   File "D:\XUB\Final Year Thesis\flask\app.py", line 8, in <module>
   regressor = pickle.load(open(filename, 'rb'))
   ModuleNotFoundError: No module named 'sklearn.linear_model.base'

I have following versions

  • scikit-learn 0.24.1
  • Python 3.9.1
desertnaut
  • 57,590
  • 26
  • 140
  • 166
noob_python
  • 25
  • 1
  • 7

3 Answers3

1

Short Answer

Changing .base to ._base solved the problem in my case.

Somewhat Long Answer

I also faced the same problem while working using a python library. In that library, the authors imported _preprocess_data() using the following statement.

from sklearn.linear_model.base import _preprocess_data

However, that generated the same issue.

ModuleNotFoundError: No module named 'sklearn.linear_model.base'

Then, changing the import statement by the following line solved the problem.

from sklearn.linear_model._base import _preprocess_data
Md. Sabbir Ahmed
  • 850
  • 8
  • 22
1

In my case, I simply opened the .pkl file with notepad++. There it was written sklearn.linear_model.base. Simply deleted the word .base and saved it as is.

Then the code runs properly.

Sagar Darekar
  • 982
  • 9
  • 14
1

run pip install scikit-learn this will probably solve your problem