def inspection_performance(predicted_fraud, test_fraud):
Inspect_Rate = []
Precision=[]
Recall=[]
for i in range(1,100,1):
threshold = np.percentile(predicted_fraud, i)
precision = np.mean(test_fraud[predicted_fraud > threshold])
recall = sum(test_fraud[predicted_fraud > threshold])/sum(test_fraud)
Inspect_Rate.append(100-i)
Precision.append(precision)
Recall.append(recall)
compiled_conf_matrix = pd.DataFrame({
'İnceleme Oranı':Inspect_Rate,
'Kesinlik':Precision,
'Hatırlama':Recall,
})
return compiled_conf_matrix
我无法打印混淆矩阵结果。然后我想获得确定性、回忆和 f 分数,但我不能。这是我的代码指南。我如何通过编写类似于下面的代码来获得这个?
from sklearn.metrics import classification_report, confusion_matrix
print(confusion_matrix(y_test, y_pred))
举个例子,我想最后得到这样的结果。
print(classification_report(y_test, y_pred))
precision recall f1-score support
0 0.96 0.68 0.80 37117
1 0.14 0.67 0.23 2883
accuracy 0.68 40000
macro avg 0.55 0.68 0.52 40000
weighted avg 0.90 0.68 0.76 40000
我必须写其他东西而不是 y_test 和 y_pred。但是我不知道怎么写。
ROC-AUC曲线代码如下,仅供参考。这里应该用哪个标签代替 (y_true, y_pred)?
from matplotlib import pyplot as plt
from sklearn.metrics import roc_curve
from sklearn.metrics import auc
fpr, tpr, _ = roc_curve(test_labels.drop(np.where(np.isnan(y_pred))[0]), np.delete(y_pred, np.where(np.isnan(y_pred))[0]))
plt.plot(fpr, tpr, label='ROC curve')
plt.plot([0, 1], [0, 1], 'k--', label='Random guess')
plt.xlabel('False positive rate')
plt.ylabel('True positive rate')
plt.title('ROC curve')
plt.legend(loc="lower right")
plt.show()
print('auc: ', auc(fpr, tpr))
print(confusion_matrix(?, ?))
print(classification_report(?, ?))
在基本上有问号的地方应该得到什么?
答案 0 :(得分:0)
你的问题很模糊。你想要混淆矩阵还是分类报告?
from sklearn.metrics import confusion_matrix
print(confusion_matrix(y_true, y_pred))
哪里,
y_true:ground_truth 标签
y_pred:预测标签
现在,就您而言,该函数有两个参数:predicted_fraud、test_fraud。 test_fraud 是你的 ground_truth 吗?必须有两个标签,即欺诈或无欺诈 (1,0) 如果是,则
from sklearn.metrics import confusion_matrix
print(confusion_matrix(test_fraud.classes, predicted_fraud))
from sklearn.metrics import classification_report
target_names = ['fraud', 'No fraud']
print(classification_report(test_fraud.classes, predicted_fraud, target_names=target_names))
分类报告将为您提供每个类别的主要分类指标(欺诈、无欺诈),例如:准确率、召回率、f1 分数、准确率等。
此外,还有一个github link,它对我也有帮助,希望对您也有帮助。
答案 1 :(得分:0)
我解决了这个问题。应该发生的事情如下。
onChangeIntervento(intervento: number) {
this.prezzoStrutturale = intervento
this.elementoSelezionato = []
this.interventi.forEach(c => {
if(this.prezzoStrutturale == c.prezzoRiepilogo) {
this.elementoSelezionato.push(c)
}
if(this.prezzoStrutturale == c.prezzoRiepilogoTwo) {
this.elementoSelezionato.push(c)
}
})
}