This demo program shows how to calculate the
- Mean Absolute Error(mae) - residual contributes proportionally to the total amount of error, meaning that larger errors will contribute linearly to the overall error
- Mean Square Essor(mse) - is a measure of how large your residuals are spread out
- Mean Absolute Percentage Error(mape) - how far the model’s predictions are off from their corresponding outputs on average
from our previous model Predictive Model with Linear Regression.
The Output:
The code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | mae_sum = 0 mse_sum = 0 mape_sum = 0 for a, b in zip(Y, X): prediction = model.predict(b.reshape(-1, 1)) mae_sum += abs(a - prediction) mse_sum += (a - prediction)**2 mape_sum += (abs((a - prediction))/a) mae = mae_sum / len(Y) mse = mse_sum / len(Y) mape = mape_sum/len(Y) print('MAE=' + str(mae)) print('MSE=' + str(mse)) print('MAPE=' + str(mape)) |
No comments:
Post a Comment