深度学习入门 (6):神经网络的学习

y = [0.1,0.05,0.6,0.0,0.05,0.1,0.0,0.1,0.0,0.0]
t = [0,0,1,0,0,0,0,0,0,0]

均方误差

import numpy as np
def mean_squared_error(y,t):
    return 0.5*np.sum((y-t)**2)
mean_squared_error(np.array(y),np.array(t))

交叉熵误差

def cross_entropy_error(y,t):
    delta = 1e-7
    return -np.sum(t*np.log(y+delta))
cross_entropy_error(np.array(y),np.array(t))
np.random.choice(60000,10)

mini-batch 交叉熵误差的

def cross_entropy_error2(y,t):
    if y.ndim == 1:
        t = t.reshape(-1,t.size)
        y = y.reshape(-1,y.size)
        
    batch_size = y.shape[0]
    return -np.sum(t*np.log(y+1e-7))/batch_size
def cross_entropy_error3(y,t):
    if y.ndim == 1:
        t = t.reshape(-1,t.size)
        y = y.reshape(-1,y.size)
        
    batch_size = y.shape[0]
    return -np.sum(np.log[y[np.arange(batch_size),t]])/batch_size
posted @ 2025-03-06 20:53  屈臣  阅读(6)  评论(0)    收藏  举报