【发布时间】:2021-02-20 02:02:57
【问题描述】:
我正在尝试通过运行以下代码检查模型是否正确预测亚马逊评论是正面还是负面:
def predict_category(s, X_train=X_train, model=model):
pred = model.predict([s])
return y_train.loc[y_train[pred[0]]]
predict_category('These deserved a 5 star because of the price and their strength. Will be buying again when we eventually run out.')`
如果评论是正面的,它必须返回True,如果是负面的,它必须返回False。
它确实以下面的 KeyError 的形式返回了正确的答案,但有什么解决方法吗?
KeyError Traceback (most recent call last) <ipython-input-66-5ab570b98937> in <module> pandas\_libs\index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type()
KeyError: True
【问题讨论】:
标签: python pandas naivebayes