[英]Generate negative predictive value using cross_val_score in sklearn for model performance evaluation
As part of evaluating a model's metrics, I would like to use cross_val_score in sklearn to generate negative predictive value for the model.作为评估模型指标的一部分,我想在 sklearn 中使用 cross_val_score 来为模型生成负预测值。
In example below, I set the 'scoring' parameter within cross_val_score to calculate and print 'precision' (mean and standard deviations from 10-fold cross-validation) for positive predictive value of the model:在下面的示例中,我在 cross_val_score 中设置了“评分”参数来计算和打印模型的阳性预测值的“精度”(10 倍交叉验证的平均值和标准偏差):
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_score
log=LogisticRegression()
log_prec = cross_val_score(log, x, y, cv=10, scoring='precision')
print("PPV(mean, std): ", np.round(log_prec.mean(), 2), np.round(log_prec.std(), 2))
For a binary classification problem you can invert the label definition. 对于二进制分类问题,您可以反转标签定义。 Then the PPV will correspond to the NPV in you original problem
那么PPV将与您原始问题中的NPV相对应
You can use make_scorer<\/code><\/a> to pass in
pos_label=0<\/code> to the precision score function (
metrics.precision_score<\/code><\/a> ) to get NPV.
您可以使用
make_scorer<\/code><\/a>将
pos_label=0<\/code>传递给精度评分函数 (
metrics.precision_score<\/code><\/a> ) 以获取 NPV。
Like this:
像这样:
from sklearn.metrics import make_scorer, precision_score
npv = cross_val_score(log, x, y, cv=10, scoring=make_scorer(precision_score, pos_label=0))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.