首页 > 代码库 > 『cs231n』线性分类器最优化

『cs231n』线性分类器最优化

 

 最优化策略

1.差劲的方案,随机搜索

bestloss = float(‘inf‘)  # 无穷大
for num in range(1000):
    W = np.random.randn(10, 3073) * 0.0001
    loss = L(X_train, Y_train, W)
    if loss < bestloss:
        bestloss = loss
        bestW = W

scores = bsetW.dot(Xte_cols)
Yte_predict = np.argmax(score, axis = 0)
np.mean(Yte_predict == Yte)

核心思路:迭代优化

2.浪费的方案,随机本地搜索

W = np.random.randn(10, 3073) * 0.001
bestloss = float(‘inf‘)
for i in range(1000):
    step_size = 0.0001
    Wtry = np.random.randn(10, 3073) * step_size
    loss = L(Xtr_cols, Ytr, Wtry)
    if loss < bestloss:
        W = Wtry
        bestloss = loss

 3.跟随梯度

 

『cs231n』线性分类器最优化