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

Function mse

machine_learning/scoring_functions.py:40–58  ·  view source on GitHub ↗

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

(predict, actual)

Source from the content-addressed store, hash-verified

38
39# Mean Squared Error
40def mse(predict, actual):
41 """
42 Examples(rounded for precision):
43 >>> actual = [1,2,3];predict = [1,4,3]
44 >>> float(np.around(mse(predict,actual),decimals = 2))
45 1.33
46
47 >>> actual = [1,1,1];predict = [1,1,1]
48 >>> float(mse(predict,actual))
49 0.0
50 """
51 predict = np.array(predict)
52 actual = np.array(actual)
53
54 difference = predict - actual
55 square_diff = np.square(difference)
56
57 score = square_diff.mean()
58 return score
59
60
61# Root Mean Squared Error

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected