Browse and solve 1,200+ machine learning coding challenges on Deep-ML. Filter by difficulty (beginner, intermediate, advanced) and category (linear algebra, machine learning, deep learning, NLP, computer vision). Write Python solutions in the browser and get instant feedback against test cases.
Implement a function to calculate the Mean Absolute Error (MAE) between two arrays of actual and predicted values. The MAE is a metric used to measure the average magnitude of errors in a set of predictions without considering their direction.
Your function should return the MAE as a float value.
y_true = np.array([3, -0.5, 2, 7]), y_pred = np.array([2.5, 0.0, 2, 8])
0.5
The MAE is the mean of absolute differences: (|3-2.5| + |-0.5-0| + |2-2| + |7-8|) / 4 = (0.5 + 0.5 + 0 + 1) / 4 = 0.5