简体   繁体   English

在R中为插入符号生成调整参数

[英]generating tuning parameter for Caret in R

I've been trying to use the caret package to do k-folds validation of a model. 我一直在尝试使用插入符号包对模型进行k折验证。 I've run lm() to some success, but when I try and do it with caret it fails. 我已经运行lm()取得了一些成功,但是当我尝试用插入符号执行操作时,它失败了。 steps: 脚步:

 train_control <- trainControl(method="cv", number=10)


 grid <- expand.grid(.fL=c(0), .usekernel=c(FALSE))


 model <- train(FantasyPTS ~ Shoots + Height + Weight + Birthyear + 
              age + Draft_Year + Overall_Draft_Num + Draft_Team + Draft_Age + 
             GAA + SVPCT + GSAA + QS + QS. + RBS + GPS, data=nhlgoalies, trControl=train_control, method="lm", tuneGrid=grid)

results in 结果是

Error in train.default(x, y, weights = w, ...) : 
  The tuning parameter grid should have columns intercept

my understanding was always that the model itself should generate the intercept. 我的理解始终是模型本身应该生成拦截。 I know from reading the docs it needs the parameter intercept but I don't know how to generate it before the model itself is created? 通过阅读文档,我知道它需要参数拦截,但是我不知道如何在创建模型本身之前生成它?

You dont give a link to a dataset, so I generate my one for example. 您没有提供指向数据集的链接,因此,例如,我生成了一个。

    ## Make data
ncol <- 3
Xs       <- matrix(rnorm(300*ncol), nrow = 300, ncol = ncol) %>% as.tibble()
Yvec     <- rnorm(300)
train_control <- trainControl(method="cv", number=10)

    ## Fit lm model using train
fit  <- train(x= Xs, y = Yvec, method = "lm",trControl = train_control)

So you just don't need to specify tuneGrid parameter and will be ok. 因此,您只需要指定tuneGrid参数就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM