Linear RegressionModel Evaluation
To build a reliable linear regression model, we need a way to measure how good (or bad) its predictions are. Think of it like taking a test: you need a score to know how well you did! In machine learning, we call these scoring methods loss functions.
What do you think is the goal of our model when it comes to "loss"?
Mean-Squared Error (MSE)
One of the most popular loss functions is Mean-Squared Error (MSE). It simply answers the question: on average, how far off are our predictions?
MSE works by finding the difference between our predicted value and the actual value (an "error"), squaring that difference, and taking the average across all data points. Wait, why do we square it? Because squaring ensures that negative errors (guessing too low) and positive errors (guessing too high) don't
MSE Formula
Where:
n : the number of data points.- : the actual, true value.
- : our model's predicted value.
R-Squared
While MSE tells us how big our errors are, we sometimes want to know "how much of the mystery did we solve?". To find out, we use a goodness-of-fit measure called R-squared.
R-squared tells us what percentage of the changes (variance) in our target variable () can be explained by our feature (). A perfect model would have an R-squared of
R-Squared Formula
The formula essentially compares our model to a simple "baseline" (predicting the average value every time) to see how much improvement we've made!
To build intuition for yourself, try changing the weight and bias terms in the interactive applet below to see how the MSE and R-squared values respond to different lines. Notice how a better fitting line decreases the MSE and increases the R-squared!
Selecting An Evaluation Metric
There is no single "best" evaluation metric; it depends on your specific goal!
- If you want to heavily punish large errors and don't care that the error is measured in "squared units", you use MSE.
- If you'd rather look at the standard "average distance" without squaring things, you might use Mean Absolute Error (MAE).
Whatever the case, your choice of evaluation metric should reflect what you actually care about when measuring the success of your predictions.