在R中为Caret生成调优参数

我一直在尝试使用caret包对模型进行k折验证。我已经成功运行了lm()函数,但在尝试使用caret时却失败了。步骤如下:

 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)

结果是

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

我一直认为模型本身应该生成截距。我从文档中了解到它需要截距参数,但我不知道如何在模型创建之前生成它?


回答:

你没有提供数据集的链接,所以我为示例生成了一个数据集。

    ## Make datancol <- 3Xs       <- matrix(rnorm(300*ncol), nrow = 300, ncol = ncol) %>% as.tibble()Yvec     <- rnorm(300)train_control <- trainControl(method="cv", number=10)    ## Fit lm model using trainfit  <- train(x= Xs, y = Yvec, method = "lm",trControl = train_control)

所以你只需不指定tuneGrid参数就可以了。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注