Error while performing gridsearch in R

r
gridsearch

#1

TrainData <- train[,1:119] # All the variables selected

TrainClasses <- train[,120] #Target variable (categorical) eg. (1,2,3,4,5,6,7,8)

xgboost1 <- train(TrainData, TrainClasses,

  •              method = "xgbTree",
    
  •              preProcess = c("center", "scale"),
    
  •              tuneLength = 10,
    
  •              trControl = trainControl(method = "cv"))
    

Something is wrong; all the RMSE metric values are missing:
RMSE Rsquared
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 :400 NA’s :400
Error in train.default(TrainData, TrainClasses, method = “xgbTree”, preProcess = c(“center”, :
Stopping
In addition: There were 50 or more warnings (use warnings() to see the first 50)

Can anyone help me with this error.? How to get rid of this error.
“Something is wrong; all the RMSE metric values are missing:”

Dataset : Kaggle Prudential Life Insurance problem


#2

hello @Rohit_Nair,

try setting the metric to “Accuracy” inside the train function.
RMSE is applicable for numeric prediction problems but we need to use Accuracy for classification models.


#3

I did that but it is saying "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 :400 NA’s :400

Now what to do ?


#4

ok.
In that case check if there are missing values in data.
If that is not the case please check if your response variable is numeric or categorical.


#5

hello @Rohit_Nair,

One more thing can be that xgboost needs all data to be numeric.

train.matrix = as.matrix(train_xg)
mode(train.matrix) = "numeric"
xgboost1 <- train(train.matrix, Survived,
                  method = "xgbTree",metric = "Accuracy",
                  tuneLength = 10,
                  trControl = trainControl(method = "cv")) 

Hope this helps!!


#6

Thanks @shuvayan for ur help. The problem is resolved :slight_smile: :slight_smile:

Thankyou very much :slightly_smiling:


#7

Hi shuvayan

I tried all what you said but still getting same error, there are no missing values.
x= training[,-c(1,2,3,4,6,15)]
y = training$is_click
fit_svm <- train(x,y,method = ‘svmLinear’,
metric = “Accuracy”,
preProcess=c(“center”,“scale”),
trControl = trainControl(method = ‘repeatedcv’,number = 2))

Getting the error
Something is wrong; all the Accuracy metric values are missing:

These are the warning messages :-
Warning messages:
1: In FUN(newX[, i], …) : NAs introduced by coercion
2: In FUN(newX[, i], …) : NAs introduced by coercion
3: In FUN(newX[, i], …) : NAs introduced by coercion
4: In FUN(newX[, i], …) : NAs introduced by coercion
5: model fit failed for Fold1.Rep1: C=1 Error in if (any(co)) { : missing value where TRUE/FALSE needed

6: In FUN(newX[, i], …) : NAs introduced by coercion
7: In FUN(newX[, i], …) : NAs introduced by coercion
8: In FUN(newX[, i], …) : NAs introduced by coercion
9: In FUN(newX[, i], …) : NAs introduced by coercion
10: model fit failed for Fold2.Rep1: C=1 Error in if (any(co)) { : missing value where TRUE/FALSE needed

11: In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, … :
There were missing values in resampled performance measures.

Can you tell me what is wrong ?