+3 votes
in Programming Languages by (77.8k 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

+1 vote
by (355k points)
selected by
 
Best answer

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

by (73.6k points)
You can also try the following to compute MSE:

 mse = ((preds-y_true)**2).mean()

...