SVM影像组学特征

近期做一个影像组学的分类模型

做的是一个胃癌T分期的模型,我刷选统计出一些胃癌区域的特征,如图:有癌症面积、体积等等

下面要做一个SVM(支持向量机)分类的模型,导入该文件,进行二分类,代码如下:

python 复制代码
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.metrics import classification_report, confusion_matrix

# 加载数据
data_path = '../data/data.xlsx'
data = pd.read_excel(data_path, sheet_name='class2T2_T34')

# 准备数据
X = data.drop(['Filename', 'label'], axis=1)  # 删除非特征列
y = data['label']  # 标签列

# 分割数据为训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# 特征缩放
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

# 创建SVM分类器

# 线性核
# svm_classifier = SVC(kernel='linear', decision_function_shape='ovo')
# 多项式核(Polynomial Kernel)
svm_classifier = SVC(kernel='poly', degree=3, coef0=1, decision_function_shape='ovo')
# 径向基函数核(Radial Basis Function, RBF Kernel)
# svm_classifier = SVC(kernel='rbf', gamma='scale', decision_function_shape='ovo')
# Sigmoid核
# svm_classifier = SVC(kernel='sigmoid', coef0=1, decision_function_shape='ovo')


# 训练模型
svm_classifier.fit(X_train, y_train)

# 预测测试集结果
y_pred = svm_classifier.predict(X_test)

# 评估模型
print("Confusion Matrix:")
print(confusion_matrix(y_test, y_pred))
print("\nClassification Report:")
print(classification_report(y_test, y_pred))

运行结果如下:

可以看出能达到85%的准确度,说明模型能够很好的区分,需要注意,如果你的分类效果不理想,我的代码中给出了很多的核,试试不同的核运行的效果

相关推荐
Theodore_10221 小时前
机器学习(3)梯度下降
人工智能·机器学习
JJJJ_iii3 小时前
【机器学习01】监督学习、无监督学习、线性回归、代价函数
人工智能·笔记·python·学习·机器学习·jupyter·线性回归
Han.miracle4 小时前
数据结构——二叉树的从前序与中序遍历序列构造二叉树
java·数据结构·学习·算法·leetcode
mit6.8246 小时前
前后缀分解
算法
你好,我叫C小白6 小时前
C语言 循环结构(1)
c语言·开发语言·算法·while·do...while
weixin_519535779 小时前
从ChatGPT到新质生产力:一份数据驱动的AI研究方向指南
人工智能·深度学习·机器学习·ai·chatgpt·数据分析·aigc
寂静山林9 小时前
UVa 10228 A Star not a Tree?
算法
Neverfadeaway9 小时前
【C语言】深入理解函数指针数组应用(4)
c语言·开发语言·算法·回调函数·转移表·c语言实现计算器
Madison-No710 小时前
【C++】探秘vector的底层实现
java·c++·算法
Swift社区10 小时前
LeetCode 401 - 二进制手表
算法·leetcode·ssh