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%的准确度,说明模型能够很好的区分,需要注意,如果你的分类效果不理想,我的代码中给出了很多的核,试试不同的核运行的效果

相关推荐
sinat_286945195 分钟前
大模型推理:部署方式与性能优化思路
人工智能·算法·缓存·chatgpt·性能优化
longlongzihan6 分钟前
LeetCode 283. 移动零:从辅助数组到双指针原地算法
c++·算法·leetcode
在所不辞兄6 分钟前
【零基础学智能仿真-42】二维随机有限元实战——把随机材料场赋给网格单元
人工智能·深度学习·算法·机器学习·工程仿真
罗湖老棍子4 小时前
Biorhythms(信息学奥赛一本通- P1639)
算法·数论·裴蜀定理·扩展欧几里得·扩展中国剩余定理
奋发向前wcx9 小时前
CSP-J复赛模拟赛4 王晨旭补题 2026.10.5
算法
这张生成的图像能检测吗12 小时前
(论文速读)LogSAD:无需训练的结构异常与逻辑异常统一检测
人工智能·机器学习·计算机视觉·大模型·多模态·异常检测
念何架构之路12 小时前
zap采样器与性能优化内幕
算法·性能优化·哈希算法
晒太羊的猫13 小时前
hot100动态规划刷题
算法·动态规划
weixin_5310946913 小时前
heap_4内存管理
java·开发语言·算法
余额瞒着我当琳13 小时前
红黑树的实现--红黑树的概念、规则、效率、结构、旋转、查找、验证
数据结构·c++·算法