Closed ghost closed 6 years ago
Is a warning (not an error) and commonly occurs if a model predicts the same value across all of the holdout samples so that there is no variance in the predictions. The consequence is that the R2 cannot be computed. That looks like it is the case here.
Alright thanks. But initially i didn't want to build a model with no variance in the predictions (doesn't make sense looking at the data), this has happened to me quite a few times now and i don't understand how to get a working prediction model. Could you elaborate a little bit on why does the model gets to think the predictions are constant ?
Sorry for the delay.
The issue is that you should center and scale the predictors before the model. The preProc
option can be used to do that:
> library(datasets)
> library(MASS)
> library(caret)
Loading required package: lattice
Loading required package: ggplot2
> DP = caret::createDataPartition(Boston$medv, p = 0.75, list = F)
>
> train = Boston[DP, ]
> test = Boston[-DP, ]
> colnames(train) = colnames(Boston)
> colnames(test) = colnames(Boston)
>
> set.seed(244)
> mlp = caret::train(
+ medv ~ .,
+ data = Boston,
+ method = "mlp",
+ trControl = trainControl(
+ method = "cv",
+ number = 3,
+ savePredictions = "final"
+ ),
+ preProc = c("center", "scale"),
+ tuneGrid = expand.grid(size = 1:3),
+ linOut = TRUE,
+ metric = "RMSE"
+ )
Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, :
There were missing values in resampled performance measures.
>
> Yp = caret::predict.train(mlp, test[, 1:13])
> summary(Yp)
Min. 1st Qu. Median Mean 3rd Qu. Max.
20.64 20.64 20.64 26.09 41.94 41.94
Hello,
I'm trying to train a multi layer perceptron for non linear regression on a dataset but it keeps giving me this error :
I tried doing it again with a R dataset to see if my data was the problem but I keep getting the error and i have no idea why.
I already tried adding or removing tuneGrid, trControl, even linOut. It will always give me constant results for some reasons.