ModuleNotFoundError:没有名为“sklearn.svm._classes”的模块

Posted

技术标签:

【中文标题】ModuleNotFoundError:没有名为“sklearn.svm._classes”的模块【英文标题】:ModuleNotFoundError: No module named 'sklearn.svm._classes' 【发布时间】:2020-10-03 05:25:28 【问题描述】:

我创建了一个预测乳腺癌的模型。现在我想在 UI 上部署我的模型,因为我正在使用烧瓶。为了连接模型,我制作了模型的 .pkl 文件,但是当我尝试通过 app.py 读取文件时,它给了我一个错误:ModuleNotFoundError: No module named 'sklearn.svm._classes' 我应该怎么做才能运行我的 app.py?

这是我的 app.py:

from flask import Flask,send_from_directory,render_template, request, url_for, redirect
from flask_restful import Resource, Api
from package.patient import Patients, Patient
from package.doctor import Doctors, Doctor
from package.appointment import Appointments, Appointment
from package.common import Common
import json
import pickle
import numpy as np


with open('config.json') as data_file:
    config = json.load(data_file)

app = Flask(__name__, static_url_path='')
api = Api(app)

api.add_resource(Patients, '/patient')
api.add_resource(Patient, '/patient/<int:id>')
api.add_resource(Doctors, '/doctor')
api.add_resource(Doctor, '/doctor/<int:id>')
api.add_resource(Appointments, '/appointment')
api.add_resource(Appointment, '/appointment/<int:id>')
api.add_resource(Common, '/common')



model_breast=pickle.load(open('model_breast.pkl','rb'))

# Routes

@app.route('/')
def index():
    return app.send_static_file('index.html')

@app.route('/predict',methods=['POST','GET'])
def predict():
    int_features=[int(x) for x in request.form.values()]
    final=[np.array(int_features)]
    print(int_features)
    print(final)
    prediction=model_breast.predict(final)
    output='0:.1f'.format(prediction[0][1], 2)

    if output==str(4):
        return render_template('../static/form.html',pred='The cancer type is MALIGNANT'
                                                       '\n This particular cell is cancerous. You belong to class: '.format(output))
    else:
        return render_template('../static/form.html',pred='The cancer type is BENIGN'
                                                       '\n This particular cell is NOT cancerous. You belong to class: '.format(output))


if __name__ == '__main__':
    app.run(debug=True,host=config['host'],port=config['port'])

Error

【问题讨论】:

在你的命令提示符下,运行python -m pip install scikit-learn 我安装了scikit包,还是报同样的错误 用样本数据检查加载的模型,看看它是否正确加载到烧瓶应用程序中。如果你正在使用它,请确保激活任何 virtualenv。 @HArdRese7 你能说清楚你在说什么吗? 【参考方案1】:

'sklearn.svm._classes' 特定于 scikit-learn 包的 0.19.2 版本。

您可以使用以下方式安装此版本:

pip install scikit-learn==0.19.2

【讨论】:

以上是关于ModuleNotFoundError:没有名为“sklearn.svm._classes”的模块的主要内容,如果未能解决你的问题,请参考以下文章

ModuleNotFoundError:没有名为“dataviz”的模块

ModuleNotFoundError:没有名为“numpy”的模块

错误:ModuleNotFoundError:没有名为“图像”的模块

ModuleNotFoundError:没有名为“knox”的模块

ModuleNotFoundError:没有名为“memoize”的模块

ModuleNotFoundError:没有名为“pssh”的模块