MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / mae

Function mae

machine_learning/scoring_functions.py:19–36  ·  view source on GitHub ↗

Examples(rounded for precision): >>> actual = [1,2,3];predict = [1,4,3] >>> float(np.around(mae(predict,actual),decimals = 2)) 0.67 >>> actual = [1,1,1];predict = [1,1,1] >>> float(mae(predict,actual)) 0.0

(predict, actual)

Source from the content-addressed store, hash-verified

17
18# Mean Absolute Error
19def mae(predict, actual):
20 """
21 Examples(rounded for precision):
22 >>> actual = [1,2,3];predict = [1,4,3]
23 >>> float(np.around(mae(predict,actual),decimals = 2))
24 0.67
25
26 >>> actual = [1,1,1];predict = [1,1,1]
27 >>> float(mae(predict,actual))
28 0.0
29 """
30 predict = np.array(predict)
31 actual = np.array(actual)
32
33 difference = abs(predict - actual)
34 score = difference.mean()
35
36 return score
37
38
39# Mean Squared Error

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected