[英]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我有以下版本
Short Answer简答
Changing .base
to ._base
solved the problem in my case.将.base
更改为._base
解决了我的问题。
Somewhat Long Answer有点长的答案
I also faced the same problem while working using a python library.在使用 python 库时,我也遇到了同样的问题。 In that library, the authors imported _preprocess_data()
using the following statement.在该库中,作者使用以下语句导入_preprocess_data()
。
from sklearn.linear_model.base import _preprocess_data
However, that generated the same issue.但是,这产生了同样的问题。
ModuleNotFoundError: No module named 'sklearn.linear_model.base' ModuleNotFoundError:没有名为“sklearn.linear_model.base”的模块
Then, changing the import statement by the following line solved the problem.然后,通过以下行更改导入语句解决了问题。
from sklearn.linear_model._base import _preprocess_data
In my case, I simply opened the.pkl file with notepad++.就我而言,我只是用 notepad++ 打开了 .pkl 文件。 There it was written sklearn.linear_model.base.那里写着 sklearn.linear_model.base。 Simply deleted the word.base and saved it asit is.只需删除 word.base 并按原样保存即可。
Then the code run properly.然后代码正常运行。
run pip install scikit-learn this will probably solve your problem运行pip 安装 scikit-learn这可能会解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.