Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Training Models in Caret Without Tuning R [closed]

It seems that when training models in caret you are almost forced into parameter tuning. I know that this is generally a good idea but what if I wanted to explicitly state a models parameters when training?

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

Something is wrong; all the RMSE metric values are missing:

    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    

Error in train.default(x, y, weights = w, ...) : Stopping In addition: Warning message: In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : There were missing values in resampled performance measures.

like image 216
Nitro Avatar asked Nov 06 '25 22:11

Nitro


1 Answers

I figured out one way, it is somewhat obscure. You must create a data frame of tuning parameters that is passed to tuneGrid, except only list 1 value for each parameter.

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
like image 103
Nitro Avatar answered Nov 09 '25 15:11

Nitro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!