modulenotfounderror:python 烧瓶上没有名为“sklearn.linear_model.logistic”的模块

时间:2021-06-09 02:22:52

标签: python scikit-learn

我在运行 http://127.0.0.1:5000/iris/1/1/1/1 时遇到问题。它不断收到内部服务器错误。我不知道为什么,它一直在这样做。我尝试了很多方法,但仍然没有奏效。它一直在说“modulenotfounderror: no module named 'sklearn.linear_model.logistic' 。”有没有办法解决这个问题。

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

1 个答案:

答案 0 :(得分:0)

查看scikit-learn的版本,可能是0.21.x。升级版本。

这是 scikit-learn 稳定版: https://github.com/scikit-learn/scikit-learn/tree/master/sklearn/linear_model