How to use Actual Formulae In Python

Mean Absolute Error (MAE) is calculated by taking the summation of the absolute difference between the actual and calculated values of each observation over the entire array and then dividing the sum obtained by the number of observations in the array.

Example:

Python3




# Python program for calculating Mean Absolute Error
  
# consider a list of integers for actual
actual = [2, 3, 5, 5, 9]
  
# consider a list of integers for actual
calculated = [3, 3, 8, 7, 6]
  
n = 5
sum = 0
  
# for loop for iteration
for i in range(n):
    sum += abs(actual[i] - calculated[i])
  
error = sum/n
  
# display
print("Mean absolute error : " + str(error))


Output

Mean absolute error : 1.8

How to Calculate Mean Absolute Error in Python?

Mean Absolute Error calculates the average difference between the calculated values and actual values. It is also known as scale-dependent accuracy as it calculates error in observations taken on the same scale. It is used as evaluation metrics for regression models in machine learning. It calculates errors between actual values and values predicted by the model. It is used to predict the accuracy of the machine learning model.

Formula:

Mean Absolute Error = (1/n) * ∑|yi – xi|

where,

  • Σ: Greek symbol for summation
  • yi: Actual value for the ith observation
  • xi: Calculated value for the ith observation
  • n: Total number of observations

Similar Reads

Method 1: Using Actual Formulae

Mean Absolute Error (MAE) is calculated by taking the summation of the absolute difference between the actual and calculated values of each observation over the entire array and then dividing the sum obtained by the number of observations in the array....

Method 2: Using sklearn

...