精确召回 pos_label python 为 one-class
precision recall pos_label python for one-class
目标:获得precision
和recall
for one-class(y_true
= 1
)
背景:我检查了http://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_curve.html#sklearn.metrics.precision_recall_curve,它指出pos_label
是positive class
的标签,并设置为1
默认。
问题:
1) 如果我只想要 positive class
的 precision
和 recall
(在本例中为 y_true
= 1
),我应该保留 pos_label
= 1
还是应该改成 pos_label = 0
?
2) 还是有更好的方法来实现我的目标?
下面我显示的是 pos_label
= 0
时的代码
import numpy as np
from sklearn.metrics import precision_recall_fscore_support
y_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 np
from sklearn.metrics import precision_recall_fscore_support
y_true = np.array(['0', '1', '1', '0', '1'])
y_pred = np.array(['1', '0', '1', '0', '1'])
#keep 1's
y_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')
目标:获得precision
和recall
for one-class(y_true
= 1
)
背景:我检查了http://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_curve.html#sklearn.metrics.precision_recall_curve,它指出pos_label
是positive class
的标签,并设置为1
默认。
问题:
1) 如果我只想要 positive class
的 precision
和 recall
(在本例中为 y_true
= 1
),我应该保留 pos_label
= 1
还是应该改成 pos_label = 0
?
2) 还是有更好的方法来实现我的目标?
下面我显示的是 pos_label
= 0
import numpy as np
from sklearn.metrics import precision_recall_fscore_support
y_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 np
from sklearn.metrics import precision_recall_fscore_support
y_true = np.array(['0', '1', '1', '0', '1'])
y_pred = np.array(['1', '0', '1', '0', '1'])
#keep 1's
y_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')