Reputation: 45
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
Upvotes: 3
Views: 6922
Reputation: 871
I got the message "No module named 'sklearn.linear_model.base'" I followed the answer above, copy _base.py into base.py, and etc. Sutitations become worse. Below is the way I solved. My situation is special. Hope someone have the same problem can refer.
Upvotes: 0
Reputation: 11
run pip install scikit-learn this will probably solve your problem
Upvotes: 1
Reputation: 11
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.
Upvotes: 1
Reputation: 881
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
Upvotes: 2