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

Function mean_absolute_error

machine_learning/linear_regression.py:113–125  ·  view source on GitHub ↗

Return sum of square error for error calculation :param predicted_y : contains the output of prediction (result vector) :param original_y : contains values of expected outcome :return : mean absolute error computed from given feature's >>> predicted_y = [3, -0.5, 2, 7]

(predicted_y, original_y)

Source from the content-addressed store, hash-verified

111
112
113def mean_absolute_error(predicted_y, original_y):
114 """Return sum of square error for error calculation
115 :param predicted_y : contains the output of prediction (result vector)
116 :param original_y : contains values of expected outcome
117 :return : mean absolute error computed from given feature's
118
119 >>> predicted_y = [3, -0.5, 2, 7]
120 >>> original_y = [2.5, 0.0, 2, 8]
121 >>> mean_absolute_error(predicted_y, original_y)
122 0.5
123 """
124 total = sum(abs(y - predicted_y[i]) for i, y in enumerate(original_y))
125 return total / len(original_y)
126
127
128def main():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected