【问题标题】:Error: The tuning parameter grid should have columns fL, usekernel, adjust. K fold Cross Validation错误:调整参数网格应该有列 fL、usekernel、adjust。 K折交叉验证
【发布时间】:2021-02-17 05:43:00
【问题描述】:

我该如何解决这个错误。我试图自己解决这个错误,但没有成功,谁能帮助我?

library(caret)
diabet<-read.csv(file.choose(),header = T,sep=",")
diabet$Outcome<-as.factor(diabet$Outcome)
# define training control
train_control<- trainControl(method="cv", number=10)
# fix the parameters of the algorithm
grid <- expand.grid(.fL=c(0), .usekernel=c(FALSE))
# train the model
model <- train(Outcome~BMI, data=diabet,
                trControl=train_control, method="nb", tuneGrid=grid)
# summarize results
print(model)

我收到此错误:

Error: The tuning parameter grid should have columns fL, usekernel, adjust

【问题讨论】:

  • 如果您包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出,则更容易为您提供帮助。从错误消息中,您似乎在grid 中缺少adjust

标签: r data-science r-caret


【解决方案1】:

如错误中所述,您缺少一个调整参数adjust。你可以这样看:

getModelInfo("nb")$nb$parameters
  parameter   class                label
1        fL numeric   Laplace Correction
2 usekernel logical    Distribution Type
3    adjust numeric Bandwidth Adjustment

如果你包含它,应该可以工作:

library(caret)
diabet = data.frame(Outcome = sample(c("Yes","No"),100,replace=TRUE),
                    BMI = runif(100))

train_control<- trainControl(method="cv", number=10)
grid <- expand.grid(.fL=c(0), .usekernel=c(FALSE),.adjust=0.5)

model <- train(Outcome~BMI, data=diabet,
                trControl=train_control, method="nb", tuneGrid=grid)

Naive Bayes 

100 samples
  1 predictor
  2 classes: 'No', 'Yes' 

No pre-processing
Resampling: Cross-Validated (10 fold) 
Summary of sample sizes: 90, 90, 91, 90, 90, 90, ... 
Resampling results:

  Accuracy   Kappa     
  0.4187879  -0.1685569

Tuning parameter 'fL' was held constant at a value of 0
Tuning
 parameter 'usekernel' was held constant at a value of FALSE
Tuning
 parameter 'adjust' was held constant at a value of 0.5

【讨论】:

    猜你喜欢
    • 2016-01-15
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-30
    • 2020-10-24
    • 2020-08-29
    • 2020-07-08
    • 2020-09-10
    相关资源
    最近更新 更多