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
计算auc和acc以及svm的demo
最新推荐文章于 2023-03-29 14:56:11 发布