导入 numpy 科学计算库

import numpy as np

y_true 表示真实标签

np.random.seed(0) y_true = np.random.randint(0,2,1000)

y_true 表示预测标签

np.random.seed(1) y_pred = np.random.randint(0,2,1000)

任务1:根据公式计算预测结果的精度

########## Begin ########## true_positive = np.sum((y_true == 1) & (y_pred == 1)) false_positive = np.sum((y_true == 0) & (y_pred == 1)) precision = true_positive / (true_positive + false_positive) ########## End ##########

任务2:根据公式计算预测结果的召回率

########## Begin ########## false_negative = np.sum((y_true == 1) & (y_pred == 0)) recall = true_positive / (true_positive + false_negative) ########## End ##########

打印结果

print("预测结果的精度是{},召回率是{}。".format(precision, recall)

# 导入 numpy 科学计算库import numpy as np# y_true 表示真实标签nprandomseed0y_true = nprandomrandint021000# y_true 表示预测标签nprandomseed1y_pred = nprandomrandint021000# 任务1:根据公式计算预测结果的精度########## Begin ##########prec

原文地址: http://www.cveoy.top/t/topic/fpF5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录