Functions, Users, and Comparative Analysis
We decided that Docs should have prime location.
Build AI products you can trust.
We’re super excited to share that Aporia is now the first ML observability offering integration to the Databricks Lakehouse Platform. This partnership means that you can now effortlessly automate your data pipelines, monitor, visualize, and explain your ML models in production. Aporia and Databricks: A Match Made in Data Heaven One key benefit of this […]
Fundamentals of ML observability
Metrics, feature importance and more
We’re excited 😁 to share that Forbes has named Aporia a Next Billion-Dollar Company. This recognition comes on the heels of our recent $25 million Series A funding and is a huge testament that Aporia’s mission and the need for trust in AI are more relevant than ever. We are very proud to be listed […]
Introduction >
Or is a software engineer at Aporia and an avid gaming enthusiast "All I need is a cold brew and the controller in my hand, and I'm good to go."
Today’s spotlight is on Root Mean Square Error (RMSE) – a pivotal evaluation metric commonly used in regression problems. Through the lens of our Production ML Academy, we’ll peel back the layers of RMSE, probing its purpose and practicality across applications such as sales forecasting, energy consumption prediction, and medical data analysis. Let’s also examine how this metric fits snugly into the production lifecycle of ML systems.
The Root Mean Square Error (RMSE) is an oft-employed measure to gauge the prediction errors of a regression model. In essence, it tells us about the distribution of the residuals (prediction errors). A lower RMSE is indicative of a better fit for the data.
RMSE is mathematically represented as:
In simpler terms, it’s the square root of the mean of the squared differences between the prediction and actual observation. This measure emphasizes larger errors over smaller ones, thus providing a more conservative estimate of model accuracy when large errors are particularly undesirable.
To make the concept of RMSE more relatable, let’s explore a straightforward example. We have a model that predicts the daily energy consumption of a building.
Here are some hypothetical data for five days:
Day 1: Actual = 500 units, Predicted = 520 units
Day 2: Actual = 600 units, Predicted = 570 units
Day 3: Actual = 580 units, Predicted = 590 units
Day 4: Actual = 650 units, Predicted = 630 units
Day 5: Actual = 700 units, Predicted = 710 units
By applying the RMSE formula, we find that the RMSE for the model’s predictions over these five days is approximately 19.49 units. This suggests that, on average, the model’s predictions deviate from the actual values by around 19.49 units, with larger errors being weighted more heavily.
Here’s how we would calculate the RMSE in Python for the data provided above:
import numpy as np # Actual values actual = np.array([500, 600, 580, 650, 700]) # Predicted values predicted = np.array([520, 570, 590, 630, 710]) # Calculate the difference between predicted and actual difference = predicted - actual # Square the differences squared_difference = difference ** 2 # Compute the mean squared difference mean_squared_difference = np.mean(squared_difference) # Finally, take the square root of the mean squared difference to get the RMSE rmse = np.sqrt(mean_squared_difference) print(f"The RMSE of the model's predictions over these five days is approximately {rmse:.2f} units.")
When you run this script, it outputs: The RMSE of the model’s predictions over these five days is approximately 19.49 units.
To highlight the difference between RMSE and Mean Absolute Error (MAE), let’s calculate the MAE for the same set of data. The MAE is calculated as the average absolute difference between the actual and predicted values.
While both RMSE and MAE measure the difference between the predicted and observed values, RMSE puts more weight on larger errors due to the squaring operation. Consequently, RMSE is more sensitive to outlier values as compared to MAE.ֿ
Let’s highlight the difference between RMSE and Mean Absolute Error (MAE), by calculating the MAE for the same set of data. The MAE is calculated as the average absolute difference between the actual and predicted values.
In Python, this can be done as follows:
import numpy as np # Actual values actual = np.array([500, 600, 580, 650, 700]) # Predicted values predicted = np.array([520, 570, 590, 630, 710]) # Calculate the absolute difference between predicted and actual absolute_difference = np.abs(predicted - actual) # Compute the mean absolute difference mae = np.mean(absolute_difference) print(f"The MAE of the model's predictions over these five days is approximately {mae:.2f} units.")
Output: The MAE of the model’s predictions over these five days is approximately 18.0 units. This indicates that, on average, our energy consumption predictions are off by around 18 units.
Comparing the two, we can see that the RMSE value is higher than the MAE value. This is because RMSE squares the differences before averaging them, thus giving more weight to larger errors. This makes RMSE a more conservative measure of model accuracy, especially when large errors are particularly undesirable.
RMSE finds its footing in diverse domains where regression problems are at the forefront:
RMSE has a central role in both the model evaluation phase and after the model is deployed, i.e., the monitoring phase. During model evaluation, RMSE serves as a measure to understand the model’s performance. Specifically, it reveals how close the predicted values are to the actual ones. An RMSE of zero indicates perfect predictions, which, in practice, is highly unlikely if not impossible.
In machine learning, RMSE is commonly used to compare the performance of different models on the same dataset. The model with the lowest RMSE is generally considered the best performer, although other metrics should also be considered for a comprehensive understanding of performance.
Once the model is deployed and starts making predictions on new data, RMSE becomes a key part of model monitoring. Continually computing and tracking RMSE for the predictions can help in identifying anomalies or a potential “concept drift” – situations where model performance degrades over time due to changes in the incoming data’s distribution.
While RMSE is an invaluable metric, it’s essential to bear in mind the following caveats:
Through this guide, we’ve journeyed into the heart of RMSE, its calculation, significance, and practical application across various domains. While it’s a go-to metric for regression problems, it also has limitations and should be used judiciously alongside other evaluation metrics. The intelligent application and understanding of RMSE can significantly augment the effectiveness of production ML systems.