0

how can I fix this error.I tried to fix the error on my own but yet unsuccessful can any one help me out?

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)

I am getting this error:

Error: The tuning parameter grid should have columns fL, usekernel, adjust
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. From the error message, it looks like you are missing an `adjust` column in `grid` – MrFlick Feb 17 '21 at 05:58

1 Answers1

2

You are missing one tuning parameter adjust as stated in the error. You can see it like this:

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

If you include it, should work:

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
StupidWolf
  • 45,075
  • 17
  • 40
  • 72