Getting an error when using glmnet in Caret
Example below
Load Libraries
library(dplyr)
library(caret)
library(C50)
Load churn data set from library C50
data(churn)
create x and y variables
churn_x <- subset(churnTest, select= -churn)
churn_y <- churnTest[[20]]
Use createFolds() to create 5 CV folds on churn_y, the target variable
myFolds <- createFolds(churn_y, k = 5)
Create trainControl object: myControl
myControl <- trainControl(
summaryFunction = twoClassSummary,
classProbs = TRUE, # IMPORTANT!
verboseIter = TRUE,
savePredictions = TRUE,
index = myFolds
)
Fit glmnet model: model_glmnet
model_glmnet <- train(
x = churn_x, y = churn_y,
metric = "ROC",
method = "glmnet",
trControl = myControl
)
Im getting the following error
Error in lognet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs, :
NA/NaN/Inf in foreign function call (arg 5)
In addition: Warning message:
In lognet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs, :
NAs introduced by coercion
I have checked and there are no missing values in the churn_x variables
sum(is.na(churn_x))
Does anyone know the answer?
See Question&Answers more detail:
os