noob_python
noob_python

Reputation: 45

No module named 'sklearn.linear_model.base'

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

Answers (4)

Peter Chen
Peter Chen

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.

  1. I test the basic function of pickle dump() and pickle load(). They work fine. Why do I have the message for ciomplicated case?
  2. I finally find out: The pickle dump file which I downloaded from github which is written by previous verions of sklearn or pickle. After I updated with my own dump, they work fine.

Upvotes: 0

AXITH CHOUDHARY
AXITH CHOUDHARY

Reputation: 11

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

Upvotes: 1

Akash kumar gupta
Akash kumar gupta

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

Md Sabbir Ahmed
Md Sabbir Ahmed

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

Related Questions