我尝试在Flask(python 2.7)中使用pickle但是当我运行Flask脚本时出现错误ValueError: non-string names in Numpy dtype unpickling
。我已经使用RandomForestClassifier对象来预测请求。我已经在下面添加了我的代码。无法在两天内解决这个错误。感谢任何帮助。
import numpy as np
from flask import Flask, jsonify, abort, request
import pickle
from sklearn.externals import joblib
my_random_forest = pickle.load(open("iris_rfc.pkl", "rb"))
app = Flask(__name__)
@app.route('/api', methods=['POST'])
def make_predict():
data = request.get_json(force=True)
predict_request = [[data['sl'], data['sw'], data['pl'], data['pw']]
predict_request = np.array(predict_request)
y_hat = my_random_forest.predict(predict_request)
output = [y_hat[0]]`enter code here`
return jsonify(results=output)
if __name__ == '__main__':
app.run(debug=True)