Machine Learning Essentials: Practical Guide in R by Kassambara Alboukadel

Machine Learning Essentials: Practical Guide in R by Kassambara Alboukadel

Author:Kassambara, Alboukadel [Kassambara, Alboukadel]
Language: eng
Format: epub
Published: 2018-03-10T00:00:00+00:00


# Build the model set.seed (123 ) elastic <- train ( medv ~ ., data = train.data, method = "glmnet" , trControl = trainControl ("cv" , number = 10 ), tuneLength = 10 ) # Model coefficients coef (elastic$ finalModel, elastic$ bestTune$ lambda) # Make predictions predictions <- elastic %>% predict (test.data) # Model prediction performance data.frame ( RMSE = RMSE (predictions, test.data$ medv), Rsquare = R2 (predictions, test.data$ medv) )

Comparing models performance :

The performance of the different models - ridge, lasso and elastic net - can be easily compared using caret . The best model is defined as the one that minimizes the prediction error.

models <- list (ridge = ridge, lasso = lasso, elastic = elastic) resamples (models) %>% summary ( metric = "RMSE" )



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.