train.default(x, y, weights = w, ...) 错误:无法确定最终调整参数 [英] Error in train.default(x, y, weights = w, ...) : final tuning parameters could not be determined

查看:56
本文介绍了train.default(x, y, weights = w, ...) 错误:无法确定最终调整参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对机器学习非常陌生,正在尝试 森林覆盖预测竞赛Kaggle,但我很早就挂了.运行以下代码时出现以下错误.

I am very new at machine learning and am attempting the forest cover prediction competition on Kaggle, but I am getting hung up pretty early on. I get the following error when I run the code below.

Error in train.default(x, y, weights = w, ...) : 
final tuning parameters could not be determined
In addition: There were 50 or more warnings (use warnings() to see the first 50)

# Load the libraries
library(ggplot2); library(caret); library(AppliedPredictiveModeling)
library(pROC)
library(Amelia)

set.seed(1234)

# Load the forest cover dataset from the csv file
rawdata <- read.csv("train.csv",stringsAsFactors = F)
#this data won't be used in model evaluation. It will only be used for the submission.
test <- read.csv("test.csv",stringsAsFactors = F)

########################
### DATA PREPARATION ###
########################

#create a training and test set for building and evaluating the model
samples <- createDataPartition(rawdata$Cover_Type, p = 0.5,list = FALSE)
data.train <- rawdata[samples, ]
data.test <- rawdata[-samples, ]

model1 <- train(as.factor(Cover_Type) ~ Elevation + Aspect + Slope + Horizontal_Distance_To_Hydrology, 
                data = data.train, 
                method = "rf", prox = "TRUE")

推荐答案

以下应该有效:

model1 <- train(as.factor(Cover_Type) ~ Elevation + Aspect + Slope + Horizontal_Distance_To_Hydrology,
                          data = data.train,
                          method = "rf", tuneGrid = data.frame(mtry = 3))

最好指定 tuneGrid 参数,该参数是一个具有可能调整值的数据框.查看 ?randomForest?train 了解更多信息.rf 只有一个调整参数 mtry,它控制为每棵树选择的特征数量.

Its always better to specify the tuneGrid parameter which is a data frame with possible tuning values. Look at ?randomForest and ?train for more information. rf has only one tuning parameter mtry, which controls the number of features selected for each tree.

您还可以运行 modelLookup 以获取每个模型的调整参数列表

You can also run modelLookup to get a list of tuning parameters for each model

> modelLookup("rf")
#  model parameter                         label forReg forClass probModel
#1    rf      mtry #Randomly Selected Predictors   TRUE     TRUE      TRUE

这篇关于train.default(x, y, weights = w, ...) 错误:无法确定最终调整参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆