In-sample performance
It's very important to know whether your regression model is useful or not. A useful model can be one that captures the structure of your training set well. One way to assess this in-sample performance is to predict on training data and calculate the mean absolute error of all predicted data points.
In this exercise, you will evaluate your in-sample predictions using MAE (mean absolute error). MAE tells you approximately how far away the predictions are from the true values.
It is calculated using the following formula, where \(n\) is the number of predictions made:
$$MAE = \frac{1}{n} \cdot \sum_{i=1}^n \text{absolute value of the }i\text{th error}$$
Available in your workspace is your model
, the regression tree that you built in the last exercises.
Diese Übung ist Teil des Kurses
Machine Learning with Tree-Based Models in R
Anleitung zur Übung
- Create
in_sample_predictions
by usingmodel
to predict on thechocolate_train
tibble. - Calculate a vector
abs_diffs
that contains the absolute differences between the in-sample-predictions and the true grades. - Calculate the mean absolute error according to the formula above.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Predict using the training set
in_sample_predictions <- predict(model,
___)
# Calculate the vector of absolute differences
abs_diffs <- ___(__$___ - ___$___)
# Calculate the mean absolute error
1 / ___ * ___