在Python中实现精确性和召回

2024-09-27 21:26:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力理解如何实现精确性和回忆性。假设clf是分类器,y_test[i]是真值,X_test[i].reshape(1,-1)是预测值,这些定义正确吗?在

精度

def testPosValueMetric(clf, X_test, y_test):
    success =0
    fail = 0
    for i in range(len(y_test)):
        if y_test[i] == 1:
            if clf.predict(X_test[i].reshape(1,-1)) == 1:
                success += 1
            else:
                fail +=1

    return (success/(success+fail))

回忆

^{pr2}$

Tags: testforif定义分类器def精度success

热门问题