Last active
March 21, 2023 08:30
-
-
Save morkapronczay/950400a93466805fceba65d098168e7c to your computer and use it in GitHub Desktop.
A snippet on how to calculate mean squared error (MSE) from scratch.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
actual = np.array([1, 2, 3, 4, 5]) | |
predicted = np.array([1.1, 1.9, 2.7, 4.5, 6]) | |
def mse(actual: np.ndarray, predicted: np.ndarray) -> float: | |
differences = np.subtract(actual, predicted) | |
squared_differences = np.square(differences) | |
return np.mean(squared_differences) | |
mse(actual, predicted) | |
# 0.27199999999999996 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment