Concept beginner · 3 min read

What is RMSE in machine learning

Quick answer
RMSE (Root Mean Squared Error) is a common regression metric that measures the square root of the average squared differences between predicted and actual values. In PyTorch, it quantifies model prediction error by computing the root of mean squared error over a dataset.
Root Mean Squared Error (RMSE) is a regression metric that quantifies the average magnitude of prediction errors by taking the square root of the mean squared differences between predicted and true values.

How it works

RMSE calculates the average magnitude of errors between predicted and actual values by first squaring the differences to remove negative signs, averaging these squared errors, then taking the square root to return to the original units. Think of it as measuring the typical distance between your model's predictions and the true values, similar to how a ruler measures distance.

Concrete example

Here is a simple PyTorch example computing RMSE for predicted vs actual values in a regression task.

python
import torch

def rmse(predictions, targets):
    return torch.sqrt(torch.mean((predictions - targets) ** 2))

# Example tensors
preds = torch.tensor([2.5, 0.0, 2.1, 7.8])
targets = torch.tensor([3.0, -0.1, 2.0, 7.5])

error = rmse(preds, targets)
print(f"RMSE: {error.item():.4f}")
output
RMSE: 0.3162

When to use it

Use RMSE when you want a metric that penalizes larger errors more heavily due to squaring, making it sensitive to outliers. It is ideal for regression problems where error magnitude matters and you want results in the same units as the target variable. Avoid using RMSE for classification tasks or when you want a metric less sensitive to outliers, like MAE (Mean Absolute Error).

Key terms

TermDefinition
RMSERoot Mean Squared Error, a regression metric measuring average prediction error magnitude.
Squared ErrorThe square of the difference between predicted and actual values.
Mean Squared Error (MSE)Average of squared errors over all data points.
RegressionA type of supervised learning predicting continuous values.

Key Takeaways

  • RMSE measures average prediction error magnitude in the same units as the target variable.
  • It penalizes larger errors more due to squaring, making it sensitive to outliers.
  • Use RMSE for regression tasks, not classification.
  • In PyTorch, RMSE can be computed easily with tensor operations.
  • RMSE is preferred when you want error magnitude interpretation and sensitivity to large deviations.
Verified 2026-04
Verify ↗