Path: blob/master/5_loss/5_loss_or_cost_function.ipynb
1141 views
Kernel: Python 3
In [2]:
In [3]:
Implement Mean Absolute Error
In [4]:
In [5]:
Out[5]:
Total error is: 2.5
Mean absolute error is: 0.5
0.5
Implement same thing using numpy in much easier way
In [32]:
Out[32]:
array([0.5, 0.5, 0. , 0. , 0.3])
In [33]:
Out[33]:
0.26
In [34]:
In [35]:
Out[35]:
0.26
Implement Log Loss or Binary Cross Entropy
In [79]:
Out[79]:
<ipython-input-79-faee82fd9f21>:1: RuntimeWarning: divide by zero encountered in log
np.log([0])
array([-inf])
In [59]:
In [58]:
Out[58]:
array([-34.53877639])
In [61]:
Out[61]:
array([1, 1, 0, 0, 1])
In [68]:
Out[68]:
[1, 1, 1e-15, 1e-15, 1]
In [70]:
Out[70]:
0.999999999999999
In [69]:
Out[69]:
[0.999999999999999, 0.999999999999999, 1e-15, 1e-15, 0.999999999999999]
In [74]:
In [71]:
Out[71]:
array([-9.99200722e-16, -9.99200722e-16, -3.45387764e+01, -3.45387764e+01,
-9.99200722e-16])
In [75]:
Out[75]:
17.2696280766844
In [76]:
In [77]:
Out[77]:
17.2696280766844
Exercise
Implement mean squared error (or MSE) in two ways,
Without using numpy (i.e. using plain python)
With the use of numpy