Reputation: 27
I want to run this code for model Validation and I am getting the error in the train()
library(caret)
diabet<-read.csv("C:/Users/Downloads/diabetes.csv")
diabet$Outcome<-as.factor(diabet$Outcome)
diabet$BMI<-as.factor(diabet$BMI)
train_control<- trainControl(method="boot", number=100)
model <-train(diabet$Outcome~diabet$BMI, trControl=train_control, method="nb")
print(model)
I am getting this type error
Something is wrong; all the Accuracy metric values are missing:
Accuracy Kappa
Min. : NA Min. : NA
1st Qu.: NA 1st Qu.: NA
Median : NA Median : NA
Mean :NaN Mean :NaN
3rd Qu.: NA 3rd Qu.: NA
Max. : NA Max. : NA
NA's :2 NA's :2
Error: Stopping
In addition: There were 50 or more warnings (use warnings() to see the first 50)
can any one help me out how can I fix the error?
Upvotes: 1
Views: 2376
Reputation: 9603
As per the documentation, there are two ways to call the train()
:
## S3 method for class 'default':
train(x, y,
method = "rf",
...,
weights = NULL,
metric = ifelse(is.factor(y), "Accuracy", "RMSE"),
maximize = ifelse(metric == "RMSE", FALSE, TRUE),
trControl = trainControl(),
tuneGrid = NULL,
tuneLength = 3)
## S3 method for class 'formula':
train(form, data, ..., weights, subset, na.action, contrasts = NULL)
From your question post, it looks like you're attempting to use the second signature, so this is how you should be implementing it:
model <-train(Outcome~BMI, data=diabet, trControl=train_control, method="nb")
This way you have a valid formula for form
, and you also pass in the required data
in the function call.
Upvotes: 1