文章目录
- 一、现象
- 二、解决方案
一、现象
......
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
recall = recall_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
......
执行语句到**“recall = recall_score(y_test, y_pred)”**这里发现报错
pos_label=1 is not a valid label. It should be one of [‘0’, ‘1’]
二、解决方案
查看y_test的数据类型,也就是标签y
df['label'].describle()
发现dtype:object,怪不得报错!
转成数值类型,即可解决
df['label'] = pd.numeric(df['label'], errors='coerce')
重新跑,跑到**“recall = recall_score(y_test, y_pred)”**,不会再报错误
解决方案:带疑问,多交流,勤动手,频思考