【学习机器学习】实验——模型评估与选择
2020-06-28 12:10:39 来源:易采站长站 作者:易采站长站整理
F1=2∗P∗RP+R=2∗TPm+TP−TNF1=cfrac{2*P*R}{P+R}=cfrac{2*TP}{m+TP-TN}F1=P+R2∗P∗R=m+TP−TN2∗TP
2.5 ROC曲线,计算AUC
这个ROC曲线老师没讲明白,还是自己查了些资料理解的,尤其是绘图的那个公式,强烈建议看一看这位答主关于ROC图的解答。实际上就是将阈值从最大的预测值逐一减小到最小的预测值,每次减小会增加一个你认为的真正例或者假正例,所以要+1。
那么具体的绘图我们还是使用sklearn自带的ROC计算,并用matplotlib绘制:代码出自,也感谢这位博主的讲解
def draw_ROC(data, target):
# 为数据增加噪声
random_state = np.random.RandomState(0)
n_samples, n_features = data.shape
data = np.c_[data, random_state.randn(n_samples, 200 * n_features)] # 按行连接数据矩阵和随机数值矩阵 # 用留出法分出训练集和测试集
data_train, data_test, target_train, target_test = train_test_split(data, target, test_size=0.2, random_state=0)
# Learn to predict each class against the other
clf = svm.SVC(kernel='linear', probability=True, random_state=random_state)
# 通过decision_function()计算得到的y_score的值,用在roc_curve()函数中
target_score = clf.fit(data_train, target_train).decision_function(data_test)
# Compute ROC curve and ROC area for each class
fpr, tpr, threshold = roc_curve(target_test, target_score) # 计算真正率和假正率,threshold阈值
roc_auc = auc(fpr, tpr) # 计算auc的值
plt.figure()
lw = 2 # 设置行距
plt.figure(figsize=(10, 10))
plt.plot(fpr, tpr, color='darkorange',
lw=lw, label='ROC curve (area = %0.2f)' % roc_auc) # 假正率为横坐标,真正率为纵坐标做曲线
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic example')
plt.legend(loc="lower right")
plt.show()
print(roc_auc)
结果大概如图,iris数据集样本量不是很大,锯齿感不明显

三、任务三
暂时不会,主要是不知道不等式应该怎么解
3.1 二项检验
3.2 t检验
参考文献
1、自助法:https://blog.csdn.net/weixin_43216017/article/details/86707415
2、ROC曲线:https://blog.csdn.net/xyz1584172808/article/details/81839230













闽公网安备 35020302000061号