十、SVM

作者: 白米饭睡不醒 | 来源:发表于2022-01-25 15:27 被阅读0次

svm

1.准备输入数据

load("TCGA-KIRC_sur_model.Rdata")
library(ROCR)
library(genefilter)
library(Hmisc)
library(e1071)

2.构建支持向量机模型

2.1.切割数据

用R包caret切割数据,生成的结果是一组代表列数的数字,用这些数字来给表达矩阵和meta取子集即可。

library(caret)
set.seed(12345679)
sam<- createDataPartition(meta$event, p = .5,list = FALSE)

train <- exprSet[,sam]
test <- exprSet[,-sam]
train_meta <- meta[sam,]
test_meta <- meta[-sam,]

2.2 train数据集建模

x=t(train)
y=as.factor(train_meta$event)
model = svm(x,y,kernel = "linear")
summary(model) 
#> 
#> Call:
#> svm.default(x = x, y = y, kernel = "linear")
#> 
#> 
#> Parameters:
#>    SVM-Type:  C-classification 
#>  SVM-Kernel:  linear 
#>        cost:  1 
#> 
#> Number of Support Vectors:  176
#> 
#>  ( 108 68 )
#> 
#> 
#> Number of Classes:  2 
#> 
#> Levels: 
#>  0 1

2.3.模型预测

用训练集构建模型,预测测试集的生死。不同于其他模型,这个预测结果是分类变量,直接预测生死,而不是prob。

x=t(test)
y=as.factor(test_meta$event)
pred = predict(model, x)
table(pred,y)
#>     y
#> pred   0   1
#>    0 142  47
#>    1  41  28

*生信技能树课程笔记

相关文章

网友评论

    本文标题:十、SVM

    本文链接:https://www.haomeiwen.com/subject/jamwhrtx.html