第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SGD 實現(xiàn) Python

SGD 實現(xiàn) Python

藍山帝景 2021-06-07 02:07:41
我知道之前已經(jīng)在 SO 上詢問過 SGD,但我想對我的代碼發(fā)表意見,如下所示:import numpy as npimport matplotlib.pyplot as plt# Generating datam,n = 10000,4x = np.random.normal(loc=0,scale=1,size=(m,4))theta_0 = 2theta = np.append([],[1,0.5,0.25,0.125]).reshape(n,1)y = np.matmul(x,theta) + theta_0*np.ones(m).reshape((m,1)) + np.random.normal(loc=0,scale=0.25,size=(m,1))# input featuresx0 = np.ones([m,1])X = np.append(x0,x,axis=1)# defining the cost functiondef compute_cost(X,y,theta_GD):       return np.sum(np.power(y-np.matmul(np.transpose(theta_GD),X),2))/2# initializationstheta_GD = np.append([theta_0],[theta]).reshape(n+1,1)alp = 1e-5num_iterations = 10000# Batch Sumdef batch(i,j,theta_GD):    batch_sum = 0    for k in range(i,i+9):        batch_sum += float((y[k]-np.transpose(theta_GD).dot(X[k]))*X[k][j])    return batch_sum# Gradient Stepdef gradient_step(theta_current, X, y, alp,i):    for j in range(0,n):            theta_current[j]-= alp*batch(i,j,theta_current)/10    theta_updated = theta_current    return theta_updated# gradient descentcost_vec = []for i in range(num_iterations):    cost_vec.append(compute_cost(X[i], y[i], theta_GD))    theta_GD = gradient_step(theta_GD, X, y, alp,i)plt.plot(cost_vec)plt.xlabel('iterations')plt.ylabel('cost')我正在嘗試批量大小為 10 的小批量 GD。我得到了 MSE 的極度振蕩行為。問題出在哪里?謝謝。PS 我正在關(guān)注 NG 的https://www.coursera.org/learn/machine-learning/lecture/9zJUs/mini-batch-gradient-descent
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 241 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號