(ML Specialization) (Code Lab)
A softmax function is used in both softmax regression and in Neural Networks when solving Multi-class Classification problems: converting a vector of values to a probability distribution. In simple terms, it converts values to probability.
Given
where
def softmax(z):
""" Softmax converts a vector of values to a probability distribution.
Args:
z (ndarray (N,)) : input data, N features
Returns:
a (ndarray (N,)) : softmax of z
"""
e_z = np.exp(z)
a = e_z / e_z.sum(axis = 0)
return a
softmax regression with 4 classes
artificial neural network with Softmax output