我试图做一个预测模型,但我找不到一种方法来解决这个与我的代码有关的问题。我已经导入了包含我从Google Colab保存的模型的pickle文件,但我似乎无法使其工作。任何类型的回应将不胜感激!
app.py
from flask import Flask, render_template, request
import pickle
import numpy as np
import joblib
model = pickle.load(open('model_car_price', 'rb'))
joblib.dump(model,'model_car_prices_data')
# imported the pickle file containing the ML model
realmodel = pickle.load(open('model_car_prices_data', 'rb'))
app = Flask(__name__)
app.debug = True
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route('/')
def man():
return render_template('home.html')
@app.route('/predict', methods=['POST'])
def home():
data1 = request.form['a']
data2 = request.form['b']
data3 = request.form['c']
data4 = request.form['d']
data5 = request.form['e']
data6 = request.form['f']
data7 = request.form['g']
arr = np.array([[data1, data2, data3, data4, data5, data6, data7]])
pred = model.predict(arr)
return render_template('after.html', data=pred)
if __name__ == "__main__":
app.run(debug=True)
试着输入
type(model)
泡菜。Load似乎返回一个numpy数组