在没有调整R的情况下训练Caret中的模型

时间:2016-09-23 16:48:07

标签: r data-mining r-caret

似乎在caret训练模型时,你几乎被迫进行参数调整。我知道这通常是一个好主意,但如果我想在训练时明确说明模型参数怎么办?

svm.nf <- train(y ~ .,
                data = nf,
                method = "svmRadial",
                C = 4, sigma = 0.25, tuneLength = 0)

出了点问题;缺少所有RMSE指标值:

    RMSE        Rsquared  
 Min.   : NA   Min.   : NA  
 1st Qu.: NA   1st Qu.: NA  
 Median : NA   Median : NA  
 Mean   :NaN   Mean   :NaN  
 3rd Qu.: NA   3rd Qu.: NA  
 Max.   : NA   Max.   : NA  
 NA's   :2     NA's   :2    
  

train.default(x,y,weights = w,...)出错:停止   另外:警告信息:   在nominalTrainWorkflow中(x = x,y = y,wts = weights,info = trainInfo,:     重新抽样的绩效指标中缺少值。

1 个答案:

答案 0 :(得分:3)

我发现了一种方式,它有点模糊。您必须创建一个传递给tuneGrid的调整参数的数据框,除了每个参数的列表1值。

params <- data.frame(C = 4,sigma=.25)

> params
  C sigma
1 4  0.25

svm.nf <- train(Point_diff ~ .,
              data = nf,
              method = "svmRadial",
              tuneGrid=params)
> svm.nf
Support Vector Machines with Radial Basis Function Kernel 

1248 samples
14 predictor

No pre-processing
Resampling: Bootstrapped (25 reps) 
Summary of sample sizes: 1248, 1248, 1248, 1248, 1248, 1248, ... 
Resampling results:

  RMSE      Rsquared 
  15.53451  0.0550965

Tuning parameter 'sigma' was held constant at a value of 0.25
Tuning parameter 'C'was held constant at a value of 4