Created
June 1, 2018 10:17
-
-
Save Ogaday/5b8f48d08e6ba8370a9db8cf8fa191e2 to your computer and use it in GitHub Desktop.
Errors
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 | |
def mae(y_true, y_pred): | |
''' | |
Caluclate mean absolute error between two vectors | |
''' | |
return np.mean(np.abs(y_pred - y_true)) | |
def smape(y_true, y_pred): | |
''' | |
Calculate symmetric mean absolute percentage error between two vectors | |
''' | |
return np.mean(np.abs(y_true - y_pred) / ((np.abs(y_true) + np.abs(y_pred)) / 2)) | |
def apply_error(df, error_func, true_col='y_true', pred_col='y_pred'): | |
''' | |
Apply error function to two columns of a dataframe. | |
''' | |
y_true, y_pred = df[true_col].copy(), df[pred_col].copy() | |
return error_func(y_true, y_pred) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment