Created
March 21, 2023 08:31
-
-
Save morkapronczay/ea9a38c80aecfaa6e4480b063cd5f114 to your computer and use it in GitHub Desktop.
A snippet on how to calculate mean squared logarithmic error (MSLE) 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 msle(actual: np.ndarray, predicted: np.ndarray) -> float: | |
log_differences = np.subtract(np.log(1 + actual), np.log(1 + predicted)) | |
squared_log_differences = np.square(log_differences) | |
return np.mean(squared_log_differences) | |
msle(actual, predicted) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment