May 2019
Intermediate to advanced
664 pages
15h 41m
English
One of the things you need to do on out-of-sample data is scale it according to the original (training) data. The predict function that comes with the psych package allows you to do this effortlessly. We put those scaled and scored values into a dataframe we can then use to make the out-of-sample predictions:
> test_reduced <- as.matrix(test[, c(-1, -95)])> test_scores <- data.frame(predict(pca_5, test_reduced, old.data = train[, c(-1, -95]))
Here, we just add the predicted and actual values:
> test_scores$testpred <- predict(earth_fit, test_scores)> test_scores$weight <- test$Weightlbs
The results look good:
> caret::postResample(pred = test_scores$testpred, obs = test_scores$weight) RMSE Rsquared MAE 7.8735 0.9468 ...