Udacity.深度学习.从机器学习到深度学习.2017-11-07

1. 练习-softmax模型

测试样例

scores = [1.0, 2.0, 3.0]
print softmax(scores)
[ 0.09003057  0.24472847  0.66524096]

scores = np.array([[1, 2, 3, 6],
                   [2, 4, 5, 6],
                   [3, 8, 7, 6]])
[[ 0.09003057  0.00242826  0.01587624  0.33333333]
 [ 0.24472847  0.01794253  0.11731043  0.33333333]
 [ 0.66524096  0.97962921  0.86681333  0.33333333]]
scores = [3.0, 1.0, 0.2]

import numpy as np

def softmax(x):
    """Compute softmax values for each sets of scores in x."""
    return np.exp(x)/np.sum(np.exp(x), axis=0)   # CODE

print(softmax(scores))

# Plot softmax curves
import matplotlib.pyplot as plt
x = np.arange(-2.0, 6.0, 0.1)
scores = np.vstack([x, np.ones_like(x), 0.2 * np.ones_like(x)])

plt.plot(x, softmax(scores).T, linewidth=2)
plt.show()
socres倍数
print(softmax(scores*10))  # 差距增加
print(softmax(scores/10))  # 差距减小
2. 交叉熵
  • Multinomial logistic classification

你可能感兴趣的:(Udacity.深度学习.从机器学习到深度学习.2017-11-07)