计算auc和acc以及svm的demo

print("下面这只是一个SVM测试")
from sklearn import svm
import warnings
warnings.filterwarnings("ignore", category=FutureWarning, module="sklearn", lineno=196)

X = [[0, 0], [0, 1], [1, 0], [1, 1]]  # training samples
y = [0, 1, 2, 3]  # training target
y_test = [0, 1, 2, 3] #test target
clf = svm.SVC()  # class
###############我需要打印两段信息(train和test分别打印)
clf.fit(X, y)  # training the svc model
print(clf.score([[0, 0], [0, 1], [1, 0], [1, 1]],[0, 1, 1, 3]))
####注意下面这两个变量改成X=图卷积+病理的向量(矩阵),y_test = 测试的标签
print(clf.score(X,y_test))


result = clf.predict([[0, 1]])  # predict the target of testing samples
print(result)  # target





print("下面是acc和auc的计算")
import numpy as np
from sklearn.metrics import accuracy_score
y_pred = [0, 2, 1, 3]
y_true = [0, 1, 2, 3]
print(accuracy_score(y_true, y_pred))


from sklearn.metrics import roc_curve, auc
y_true = np.array([1, 1, 2, 2])
y_sorce = np.array([0.1, 0.4, 0.35, 0.8])
fpr,tpr,threshold = roc_curve(y_true, y_sorce, pos_label=2)
roc_auc = auc(fpr,tpr)
print(roc_auc)


print("下面这个是取每行的最大值")
import numpy as np

x = np.array([[1,2,3],[4,5,3]])
# 先求每行最大值得下标
index_max = np.argmax(x, axis=1)# 其中,axis=1表示按行计算
# print(index_max)
print(index_max.shape)

max = x[range(x.shape[0]), index_max]
print(max)
# 注意到这里返回的是行向量
# 这可以是一种通用的方法,
# 其中range()可以是一个列向量,表示0到n
# index_max也是一个列向量,表示具体的坐标
# 这样,两个坐标组合起来就成为了二维索引

max_ = x[range(x.shape[0]), index_max].reshape(-1,1)
print(max_)
# 这样变成了列向量

# 参考博客:https://www.jb51.net/article/164928.htm
# https://blog.csdn.net/qq_16095417/article/details/79590455
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值