在不调整 R 的情况下使用 Caret 训练模型
Training Models in Caret Without Tuning R
似乎在 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
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.
我想出了一个办法,有点晦涩。您必须创建一个传递给 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
似乎在 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
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.
我想出了一个办法,有点晦涩。您必须创建一个传递给 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