为什么这不起作用,我已经安装了 sklearn。当我尝试执行它时它显示错误

问题描述 投票:0回答:1

为什么这不起作用,我已经安装了 sklearn。 我正在尝试为 ML 模型创建 api,但在这样做时遇到了很多错误。如果有人这样做,请帮助我。 我正在使用 POSTMAN 发送 html 请求,但我什至无法创建 API。

from flask import Flask, request, jsonify
import pickle
import numpy as np
app = Flask(__name__)
model=pickle.load(open('model.pkl','rb'))
@app.route('/')
def home():
    return "Hello world"


@app.route('/predict', methods=['GET', 'POST'])
def predict():
    cgpa = request.form.get('cgpa')
    iq = request.form.get('iq')
    profile_score = request.form.get('profile_score')
  #  result = {'cgpa': cgpa, 'iq': iq, 'profile_score': profile_score}
    input_query = np.array([[cgpa, iq, profile_score]])
    result = model.predict(input_query)[0]
    return jsonify({'placement': str(result)})


if __name__ == '__main__':
    app.run()
    


I'm getting this output : 

FLASK_APP = app.py
FLASK_ENV = development
FLASK_DEBUG = 0
In folder C:/Users/rohit/PycharmProjects/PlacePredictor
C:\Users\rohit\PycharmProjects\PlacePredictor\venv\Scripts\python.exe -m flask run 
Usage: python -m flask run [OPTIONS]
Try 'python -m flask run --help' for help.

Error: While importing 'app', an ImportError was raised:

Traceback (most recent call last):
  File "C:\Users\rohit\PycharmProjects\PlacePredictor\venv\Lib\site-packages\flask\cli.py", line 218, in locate_app
    __import__(module_name)
  File "C:\Users\rohit\PycharmProjects\PlacePredictor\app.py", line 5, in <module>
    model=pickle.load(open('model.pkl','rb'))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'sklearn'


Process finished with exit code 2```
python machine-learning scikit-learn model pycharm
1个回答
0
投票

在 flask 文件中添加 sklearn 的导入语句。您正在解开一个 sklearn 模型,但是 flask 包不知道 sklearn 因此您还必须将 import sklearn 添加到导入部分

© www.soinside.com 2019 - 2024. All rights reserved.