使用插入符号在 R 中进行交叉验证的 SVM [英] SVM with cross validation in R using caret

查看:68
本文介绍了使用插入符号在 R 中进行交叉验证的 SVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我使用 caret 包,以便对我拥有的数据集执行支持向量机回归和 10 折交叉验证.我正在根据 151 个变量绘制我的响应变量.我做了以下事情:-

I was told to use the caret package in order to perform Support Vector Machine regression with 10 fold cross validation on a data set I have. I'm plotting my response variable against 151 variables. I did the following:-

> ctrl <- trainControl(method = "repeatedcv", repeats = 10)
> set.seed(1500)
> mod <- train(RT..seconds.~., data=cadets, method = "svmLinear", trControl = ctrl)

我在其中

C    RMSE  Rsquared  RMSE SD  Rsquared SD
  0.2  50    0.8       20       0.1        
  0.5  60    0.7       20       0.2        
  1    60    0.7       20       0.2   

但我希望能够查看我的折叠,以及每个折叠的预测值与实际值的接近程度.我该如何看待这个?

But I want to be able to have a look at my folds, and for each of them how close the predicted values were to the actual values. How do I go about looking at this?

另外,它说:-

RMSE was used to select the optimal model using  the smallest value.
The final value used for the model was C = 0.

我只是想知道这是什么意思以及上表中的 C 代表什么?

I was just wondering what this meant and what the C stands for in the table above?

RT (seconds)    76_TI2  114_DECC    120_Lop 212_PCD 236_X3Av
38  4.086   1.2 2.322   0   0.195
40  2.732   0.815   1.837   1.113   0.13
41  4.049   1.153   2.117   2.354   0.094
41  4.049   1.153   2.117   3.838   0.117
42  4.56    1.224   2.128   2.38    0.246
42  2.96    0.909   1.686   0.972   0.138
42  3.237   0.96    1.922   1.202   0.143
44  2.989   0.8 1.761   2.034   0.11
44  1.993   0.5 1.5 0   0.102
44  2.957   0.8 1.761   0.988   0.141
44  2.597   0.889   1.888   1.916   0.114
44  2.428   0.691   1.436   1.848   0.089

这是我的数据集的片段.我正在尝试针对 151 个变量设置 RT 秒数.

This is a snipet of my dataset. I'm trying to pot RT seconds against 151 variables.

谢谢

推荐答案

您必须通过 trainControl 对象中的savePred"选项保存您的 CV 预测.我不确定您的学员"数据来自哪个包,但这里有一个使用 iris 的简单示例:

You have to save your CV predictions via the "savePred" option in your trainControl object. I'm not sure what package your "cadets" data is from, but here is a trivial example using iris:

> library(caret)
> ctrl <- trainControl(method = "cv", savePred=T, classProb=T)
> mod <- train(Species~., data=iris, method = "svmLinear", trControl = ctrl)
> head(mod$pred)
        pred        obs      setosa  versicolor   virginica rowIndex   .C Resample
1     setosa     setosa 0.982533940 0.009013592 0.008452468       11 0.25   Fold01
2     setosa     setosa 0.955755054 0.032289120 0.011955826       35 0.25   Fold01
3     setosa     setosa 0.941292675 0.044903583 0.013803742       46 0.25   Fold01
4     setosa     setosa 0.983559919 0.008310323 0.008129757       49 0.25   Fold01
5     setosa     setosa 0.972285699 0.018109218 0.009605083       50 0.25   Fold01
6 versicolor versicolor 0.007223973 0.971168170 0.021607858       59 0.25   Fold01

C"是 SVM 的调整参数之一.查看 kernlab 包中 ksvm 函数的帮助以获取更多详细信息.

The "C" is one of tuning parameters for your SVM. Check out the help for the ksvm function in the kernlab package for more details.

简单回归示例

> library(caret)
> ctrl <- trainControl(method = "cv", savePred=T)
> mod <- train(Sepal.Length~., data=iris, method = "svmLinear", trControl = ctrl)
> head(mod$pred)
      pred obs rowIndex   .C Resample
1 4.756119 4.8       13 0.25   Fold01
2 4.910948 4.8       31 0.25   Fold01
3 5.094275 4.9       38 0.25   Fold01
4 4.728503 4.8       46 0.25   Fold01
5 5.192965 5.3       49 0.25   Fold01
6 5.969479 5.9       62 0.25   Fold01

这篇关于使用插入符号在 R 中进行交叉验证的 SVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆