precision recall pos_label python for one-class

目标:获取precisionrecall值,仅针对单一类别y_true = 1)。

背景:我查看了http://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_curve.html#sklearn.metrics.precision_recall_curve,其中提到pos_labelpositive class的标签,默认设置为1

问题

1) 如果我只想获取我的positive classprecisionrecall(在这种情况下y_true = 1),我应该保持pos_label = 1,还是将其改为pos_label = 0

2) 或者是否有更好的方法来实现我的目标

下面展示的是当pos_label = 0时的代码:

import numpy as npfrom sklearn.metrics import precision_recall_fscore_supporty_true = np.array(['0', '1', '1', '0', '1'])y_pred = np.array(['1', '0', '1', '0', '1'])out = precision_recall_fscore_support(y_true, y_pred, average='weighted', pos_label = 0) 

回答:

import numpy as npfrom sklearn.metrics import precision_recall_fscore_supporty_true = np.array(['0', '1', '1', '0', '1'])y_pred = np.array(['1', '0', '1', '0', '1'])#保留1'sy_true, y_pred = zip(*[[ytrue[i], ypred[i]] for i in range(len(ytrue)) if ytrue[i]=="1"])out = precision_recall_fscore_support(y_true, y_pred, average='micro')

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注