插入符号中的xgbTree预测模型数据范围之外的所有值

插入符号中的xgbTree预测模型数据范围之外的所有值,r,regression,r-caret,R,Regression,R Caret,我正在尝试使用xgbTree训练一个插入符号中只有3个变量的回归模型。该模型仅预测2个离散值(2.3和2.6),这两个值均超出模型数据范围(2.8和4之间的5个值) 此外,当我试图计算变量重要性时,我得到以下警告消息 在FUN(newX[,i],…):max没有不丢失的参数;返回-Inf 仅列出1个变量,重要性为NaN 有人能解释我做错了什么吗?我附上了一个简单的示例代码来描述我的意思 library("caret") library("xgboost") library("plyr") x

我正在尝试使用
xgbTree
训练一个插入符号中只有3个变量的回归模型。该模型仅预测2个离散值(2.3和2.6),这两个值均超出模型数据范围(2.8和4之间的5个值)

此外,当我试图计算变量重要性时,我得到以下警告消息

在FUN(newX[,i],…):max没有不丢失的参数;返回-Inf

仅列出1个变量,重要性为NaN

有人能解释我做错了什么吗?我附上了一个简单的示例代码来描述我的意思

library("caret")
library("xgboost") 
library("plyr")

x_linear<- c(       
3.76, 3.88, 3.55, 3.47, 3.49, 3.44, 3.47, 3.49, 3.44, 3.92, 3.94, 3.55, 
3.61, 3.57, 3.46, 3.72, 3.96, 3.55, 3.34, 3.26, 3.46, 3.69, 3.69, 3.53,
3.85, 3.78, 3.55, 3.42, 3.36, 3.53, 3.98, 3.91, 3.55, 3.95, 3.82, 3.55,
3.07, 3.02, 3.44, 3.45, 3.24, 3.46, 3.83, 3.90, 3.55, 3.89, 3.96, 3.55,
3.84, 3.76, 3.55, 3.78, 3.94, 3.46, 3.28, 3.47, 3.44, 3.66, 3.66, 3.46,
3.81, 3.90, 3.46, 3.66, 3.64, 3.46, 3.70, 3.69, 3.53, 3.89, 3.85, 3.55,
3.89, 3.85, 3.55, 3.39, 3.50, 3.46, 3.59, 3.52, 3.55, 3.42, 3.29, 3.44,
3.28, 3.39, 3.46, 3.23, 3.17, 3.53, 3.57, 3.28, 3.46, 3.61, 3.60, 3.46,
3.08, 3.02, 3.44, 3.55, 3.63, 3.55, 3.60, 3.63, 3.55, 3.26, 3.27, 3.53,
3.26, 3.27, 3.53, 3.54, 3.62, 3.46, 3.54, 3.62, 3.55, 3.29, 3.30, 3.44,
3.60, 3.59, 3.55, 4.00, 3.98, 3.55, 3.25, 3.41, 3.55, 3.59, 3.66, 3.55,
3.47, 3.51, 3.46)
x <- matrix(x_linear, nrow = 45, ncol = 3, byrow = TRUE)
colnames(x) <- c("x1","x2","x3")

y <- c(4.0, 3.7, 3.4, 4.0, 4.0, 4.0, 3.1, 3.4, 4.0, 3.4, 4.0, 4.0, 
2.8, 3.4, 4.0, 4.0, 4.0, 4.0, 3.4, 3.7, 4.0, 3.7, 4.0, 4.0, 4.0,
3.4, 3.7, 3.4, 3.1, 3.1, 2.8, 3.4, 2.8, 3.7, 3.4, 3.1, 3.1, 4.0, 
3.7, 3.1, 3.7, 4.0, 2.8, 3.7, 3.7)

trainControl <- trainControl(summaryFunction=defaultSummary, 
   method="repeatedcv", repeats=3, number=8, selectionFunction="oneSE")
tuneGrid <- expand.grid(.nrounds = 100, .max_depth = 6, .eta = 0.01,
   .gamma = 0, .colsample_bytree = 1, .min_child_weight= 10)

#split into training and test sets
set.seed(1)
nSamples <- length(y)
TrainingIndexes <- createDataPartition(y, p=0.8)[[1]]
TestIndexes <- (seq(1,nSamples))[-TrainingIndexes]

# Preprocess data
procValues <- preProcess(x[TrainingIndexes,], method=c("center", "scale"))
ProcedData <- predict(procValues, x)
ProcedTrainingData <- ProcedData[TrainingIndexes,]

set.seed(1)
fit.xgb <- train(x=ProcedTrainingData, y=y[TrainingIndexes], 
method="xgbTree",tuneGrid=tuneGrid,metric="RMSE", trControl=trainControl)
Imps <- varImp(fit.xgb)
Pred_y <- predict(fit.xgb, ProcedData)
plot(y[TrainingIndexes], Pred_y[TrainingIndexes],col="blue", 
xlab="Meas", ylab="Pred")
points(y[TestIndexes], Pred_y[TestIndexes],col="red")
库(“插入符号”)
图书馆(“xgboost”)
图书馆(“plyr”)

x_linear当我运行代码时,我得到错误:
train.default中的错误(x=ProcedTrainingData,y=y[trainingindex],:当创建fit.xg时,调谐参数网格应具有nrounds、max_depth、eta、gamma、colsample_bytree、min_child_weight、subsample
列,并且在运行时不创建
tuneGrid
且在
train
函数中不调用
tuneGrid
时,它似乎会给出合理的结果,范围为2.84至4.01Hi Marijn,太好了,感谢您的输入!我没有收到错误消息-我使用的版本不需要子样本。但我想这意味着我的网格参数不好/有问题。我使用默认参数查看了结果,似乎设置的“.min_child_weight”为10是问题设置它到1我得到了更好的拟合-可能是因为数据集太小了?谢谢你的帮助!当我运行你的代码时,我得到了错误:
error in train.default(x=ProcedTrainingData,y=y[trainingindex],:当创建fit.xg时,调谐参数网格应具有nrounds、max_depth、eta、gamma、colsample_bytree、min_child_weight、subsample
列,并且在运行时不创建
tuneGrid
且在
train
函数中不调用
tuneGrid
时,它似乎会给出合理的结果,范围为2.84至4.01Hi Marijn,太好了,感谢您的输入!我没有收到错误消息-我使用的版本不需要子样本。但我想这意味着我的网格参数不好/有问题。我使用默认参数查看了结果,似乎设置的“.min_child_weight”为10是问题设置我得到了更好的拟合-可能是因为数据集太小了?谢谢你的帮助!