大家好!
我是机器学习方法的新手,有一个问题想请教。我尝试使用Caret包在R中开始这个方法,并处理我的数据集。
我有一个训练数据集(Dataset1),其中包含我感兴趣的基因(假设为基因A)的突变信息。
在Dataset1中,我有关于基因A突变的信息,以Mut或Not-Mut的形式。我使用Dataset1和SVM模型来预测输出(我选择SVM是因为它比LVQ或GBM更准确)。所以,在我的第一步,我将数据集分为训练和测试组,因为我在数据集中有测试和训练集的信息。然后我进行了10折交叉验证。我调整了我的模型,并使用测试数据集评估模型的性能(使用ROC曲线)。到这一步为止,一切顺利。
我还有另一个数据集,Dataset2,它不包含关于基因A的突变信息。我现在想做的是使用来自Dataset1的调整后的SVM模型在Dataset2上,看看它是否能给我提供关于Dataset2中基因A的突变信息,以Mut/Not-Mut的形式。我已经查看了Caret包的指南,但没有找到答案。我卡在这里,不知道该怎么办。
我不确定我选择的方法是否正确。任何建议或帮助将不胜感激。
这是我从第一个数据集调整模型的代码:
从第一个数据集中选择训练和测试模型:
M_train <- Dataset1[Dataset1$Case=='train',-1] #creating train feature data frameM_test <- Dataset1[Dataset1$Case=='test',-1] #creating test feature data framey=as.factor(M_train$Class) # Target variable for trainingctrl <- trainControl(method="repeatedcv", # 10fold cross validation repeats=5, # do 5 repititions of cv summaryFunction=twoClassSummary, # Use AUC to pick the best model classProbs=TRUE)#Use the expand.grid to specify the search space #Note that the default search grid selects 3 values of each tuning parametergrid <- expand.grid(interaction.depth = seq(1,4,by=2), #tree depths from 1 to 4 n.trees=seq(10,100,by=10), # let iterations go from 10 to 100 shrinkage=c(0.01,0.1), # Try 2 values fornlearning rate n.minobsinnode = 20)# Set up for parallel processing#set.seed(1951)registerDoParallel(4,cores=2)#Train and Tune the SVMsvm.tune <- train(x=M_train, y= M_train$Class, method = "svmRadial", tuneLength = 9, # 9 values of the cost function preProc = c("center","scale"), metric="ROC", trControl=ctrl) # same as for gbm above#Finally, assess the performance of the model using the test data set.#Make predictions on the test data with the SVM Modelsvm.pred <- predict(svm.tune,M_test)confusionMatrix(svm.pred,M_test$Class)svm.probs <- predict(svm.tune,M_test,type="prob") # Gen probs for ROCsvm.ROC <- roc(predictor=svm.probs$mut, response=as.factor(M_test$Class), levels=y))plot(svm.ROC,main="ROC for SVM built with GA selected features")
所以,我在这里卡住了,如何使用svm.tune模型来预测Dataset2中基因A的突变?
提前感谢,
回答:
现在你只需使用你构建和调整的模型,并使用predict
来进行预测:
D2.predictions <- predict(svm.tune, newdata = Dataset2)
关键是要确保在这个集合中,你有所有相同的预测变量,并且列名相同(在我的偏执世界中,顺序也相同)。
D2.predictions
将包含你对未标记数据的预测类别。