[英]modulenotfounderror: no module named 'sklearn.linear_model.logistic' on python flask
I had a problem running my http://127.0.0.1:5000/iris/1/1/1/1 .我在运行http://127.0.0.1:5000/iris/1/1/1/1时遇到问题。 It keeps getting an internal server error.它不断收到内部服务器错误。 I don't know why and It kept doing it.我不知道为什么,它一直在这样做。 I tried many ways but it still didn't work.我尝试了很多方法,但仍然没有奏效。 Its kept saying "modulenotfounderror: no module named 'sklearn.linear_model.logistic'."它一直说“modulenotfounderror:没有名为'sklearn.linear_model.logistic'的模块。” Is there a way to resolve this.有没有办法解决这个问题。
from flask import Flask, render_template
from flask import jsonify
from datetime import datetime
import numpy as np
import pandas as pd
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import LogisticRegression
from mpl_toolkits import mplot3d
from sklearn.datasets import load_iris
from sklearn import datasets
import csv
import joblib
app = Flask(__name__)
def predict(sepal_length, sepal_width, petal_length, petal_width):
test_data = np.array([sepal_length, sepal_width, petal_length,petal_width])
test_data = test_data.reshape(1,-1)
file = open("data/iris.pkl","rb")
trained_model = joblib.load(file)
prediction = trained_model.predict(test_data)
return prediction
@app.route("/iris/<sepal_length>/<sepal_width>/<petal_length>/<petal_width>")
def iris(sepal_length, sepal_width, petal_length, petal_width):
result=predict(np.double(sepal_length),
np.double(sepal_width),
np.double(petal_length),
np.double(petal_width))
if result[0]==0:
hasil='Setosa'
elif result[0]==1:
hasil='Versicolor'
else:
hasil='Virginica'
return hasil
Check the version of scikit-learn, maybe it is 0.21.x.检查scikit-learn的版本,可能是0.21.x。 upgrade the version.升级版本。
Here is scikit-learn stable: https://github.com/scikit-learn/scikit-learn/tree/master/sklearn/linear_model这是 scikit-learn 稳定版: https://github.com/scikit-learn/scikit-learn/tree/master/sklearn/linear_model
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.