我正在尝试将变量“预测”从 FLASK 部署到 ID = 预测的单元格中。该变量在应用程序中正确计算,我只是无法在 html 表中部署和显示它...如果您能告诉我如何继续,我将非常感激。我完成了模型中最困难的部分,但现在无法部署它。提前致谢import numpy as npfrom flask import Flask, request, render_templateimport pickleimport pandas as pdapp = Flask(__name__)model = pickle.load(open('logreg.pkl', 'rb'))@app.route('/')def home(): return render_template('index.html')@app.route('/predict',methods=['POST'])def predict(): int_features = [str(x) for x in request.form.values()] final_features = np.array(int_features) df = pd.read_csv('list_last_update.csv') home_team = df[df['Name']==final_features[0]] away_team = df[df['Name']==final_features[1]] X1 = np.array(home_team[['OVA', 'ATT']]) X2 = np.array(away_team[['OVA', 'ATT']]) X = np.concatenate((X1, X2), axis=None).astype(int) X = X.reshape(1, -1) prediction = model.predict(X) return render_template('index.html') if __name__ == "__main__": app.run(host='0.0.0.0',port=8080)``<td> <div class="autocomplete" style="width:300px;"><input id="away_team" type="text" name="team2" placeholder="Away Team" required="required" /></div></td><button type="submit" class="btn btn-primary btn-block btn-large">Print team rates</button></form><td> <input id="prediction" type="number" style="text-align:center"/></td><td><input id="draw_game_odd" type="number" style="text-align:center"/></td><td><input id="away_team_odd" type="number" style="text-align:center"/></td>
1 回答
慕婉清6462132
TA贡献1804条经验 获得超2个赞
您可以将prediction
变量传递给 render_tempalte 作为kwarg
prediction = model.predict(X) return render_template('index.html', prediction=prediction)
然后在 HTML 文件中访问/插入预测。例如
<div> {{ prediction }} </div
添加回答
举报
0/150
提交
取消