“列表"对象没有属性“预测" [英] 'list' object has no attribute 'predict'
本文介绍了“列表"对象没有属性“预测"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用烧瓶部署乳腺癌检测ml模型.这是错误:
I want to deploy a breast cancer detection ml model using flask. here's the error:
File "C:\Users\sakshi sanket\Desktop\Breastcancer\app.py", line 22, in predict
output = model.predict(df)
AttributeError: 'list' object has no attribute 'predict'
这是代码:
app.py
import numpy as np
import pandas as pd
from flask import Flask, request, render_template
import pickle
app = Flask(__name__, template_folder="template")
model = pickle.load(open('breast_cancer_detector.pickle', 'rb'))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
input_features = [float(x) for x in request.form.values()]
features_value = [np.array(input_features)]
features_name = ['id', 'diagnosis', 'radius_mean', 'texture_mean', 'perimeter_mean', 'area_mean', 'smoothness_mean', 'compactness_mean', 'concavity_mean', 'concave points_mean', 'symmetry_mean', 'fractal_dimension_mean', 'radius_se', 'texture_se', 'perimeter_se', 'area_se', 'smoothness_se', 'compactness_se', 'concavity_se', 'concave points_se', 'symmetry_se', 'fractal_dimension_se', 'radius_worst', 'texture_worst', 'perimeter_worst', 'area_worst', 'smoothness_worst', 'compactness_worst', 'concavity_worst', 'concave points_worst', 'symmetry_worst', 'fractal_dimension_worst']
df = pd.DataFrame(features_value, columns=features_name)
output = model.predict(df)
if output == 0:
res_val = "** breast cancer **"
else:
res_val = "no breast cancer"
return render_template('index.html', prediction_text='Patient has {}'.format(res_val)
if __name__ == "__main__":
app.run(port='8080', debug=True)
请帮助我.
推荐答案
尝试 output = model [0] .predict(df)
.由于它是一个列表,因此使用[0]应该引用一个项目.
Try output = model[0].predict(df)
. Since it is a list, using [0] should reference a single item.
这篇关于“列表"对象没有属性“预测"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文