我训练并保存了以下模型
filename = 'finalized_model.sav'
pickle.dump(rf, open(filename, 'wb'))
现在我正在编写一个获取测试数据集的Web服务,因此我加载了模型并预测了概率
def getCuisine():
content=jsonify(request.json)
test = pd.io.json.json_normalize(request.json)
tfidf_vect = pickle.load(open("vectorizer.pickle", "rb"))
test['ingredients'] = [str(map(makeString, x)) for x in test['ingredients']]
test_transform = tfidf_vect.transform(test['ingredients'].values)
le = preprocessing.LabelEncoder()
X_test = test_transform
y_test = le.fit_transform(test['cuisine'].values)
# load the model
filename = 'finalized_model.sav'
loaded_model = pickle.load(open(filename, 'rb'))
#predict
predicted_labels = loaded_model.predict_proba(X_test)
但是我遇到了错误
TypeError: '<' not supported between instances of 'NoneType' and 'int'
第predicted_labels = loaded_model.predict_proba(X_test)
行
我想念什么?
编辑:
根据评论,我在下面尝试了
content=request.json()
test = pd.io.json.json_normalize(content)
但是随后出现错误TypeError: 'list' object is not callable
。请参阅下面的示例输入。
不过,不要以为阅读请求是问题所在。我尝试使用以下本地文件读取panda,但仍收到原始错误TypeError: '<' not supported between instances of 'NoneType' and 'int'
test = pd.read_json('./test.json')
样本输入
[
{
"id": 25693,
"cuisine": "southern_us",
"ingredients": [
"plain flour",
"ground pepper",
"salt",
"tomatoes",
"ground black pepper",
"thyme",
"eggs",
"green tomatoes",
"yellow corn meal",
"milk",
"vegetable oil"
]
}
]