【发布时间】:2020-03-04 06:06:12
【问题描述】:
我是数据科学的新手,我能够构建模型并将管道与 onehotencoder 一起放置。但是,当我调用我构建的函数时,它会出错。请看下文,请指教。提前致谢!
clf = Pipeline(steps=[('ohe', OneHotEncoder()),
('rfc', RandomForestClassifier(n_estimators=1000,criterion="entropy",max_features=None))])
pickle.dump(clf,open('model.pkl','wb'))
# load model
model = pickle.load(open('model.pkl','rb'))
def predict(A,B,C,D,E,F,G):
result = model.predict(x)
# send back to browser
output = {'results': int(result[0])}
# return data
return jsonify(results=output)
调用函数:
predict('A','B','C','D','E','F','G')
错误:
NotFittedError: This OneHotEncoder instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
【问题讨论】:
标签: python function machine-learning error-handling data-science