+3 votes
in Programming Languages by (17.9k points)
I want to compute the mean square error using predicted probabilities and true labels of the data.

MSE = 1/n * sum(y_tru - y_pred)**2

Is there any Python function for the above formula?

1 Answer

0 votes
by (31.4k points)

You can use the following one-liner code to compute MSE using predicted probabilities and true labels of the data.

>>> import numpy as np
>>> preds=np.array([0.43,0.98,0.67,0.87,0.34,0.45])
>>> y_true = np.array([1,0,1,1,0,0])
>>> mse=(1/len(preds))*np.sum(np.square(preds-y_true))
>>> mse
0.2881999999999999

...