解决问题:pos_label=1 is not a valid label. It should be one of [‘0‘, ‘1‘]


一、现象

......
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)”**,不会再报错误


解决方案:带疑问,多交流,勤动手,频思考

相关推荐

  1. CSS 1PX Border问题解决

    2024-04-28 11:42:09       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-28 11:42:09       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-28 11:42:09       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-28 11:42:09       87 阅读
  4. Python语言-面向对象

    2024-04-28 11:42:09       96 阅读

热门阅读

  1. python读取文件

    2024-04-28 11:42:09       27 阅读
  2. PYTHON 访问NVD获取漏洞信息保存到本地数据库

    2024-04-28 11:42:09       34 阅读
  3. 软件安装与配置

    2024-04-28 11:42:09       26 阅读
  4. 自动化生产线的常见问题及维护方法

    2024-04-28 11:42:09       33 阅读
  5. 对象存储服务中对象业务的非标接口

    2024-04-28 11:42:09       30 阅读
  6. 当服务器遭到攻击怎么办?

    2024-04-28 11:42:09       25 阅读
  7. 【C++】6-11 停车场收费问题 分数 20

    2024-04-28 11:42:09       32 阅读
  8. Linux 下一些简单配置和软件安装

    2024-04-28 11:42:09       41 阅读