简体   繁体   中英

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 . 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'." 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. upgrade the version.

Here is scikit-learn stable: https://github.com/scikit-learn/scikit-learn/tree/master/sklearn/linear_model

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM