国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

免費(fèi)做外貿(mào)的網(wǎng)站深圳谷歌推廣公司

免費(fèi)做外貿(mào)的網(wǎng)站,深圳谷歌推廣公司,百度愛采購(gòu)下載app,網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)前言文章目錄 [toc]數(shù)據(jù)數(shù)據(jù)集實(shí)際值估計(jì)值 梯度下降算法估計(jì)誤差代價(jià)函數(shù)學(xué)習(xí)率參數(shù)更新 Python實(shí)現(xiàn)導(dǎo)包數(shù)據(jù)預(yù)處理迭代過(guò)程結(jié)果可視化完整代碼 結(jié)果可視化線性擬合結(jié)果代價(jià)變化 數(shù)據(jù) 數(shù)據(jù)集 ( x ( i ) , y ( i ) ) , i 1 , 2 , ? , m \left(x^{(i)} , y^{(i)}\right) , i 1 ,…

文章目錄

    • @[toc]
      • 數(shù)據(jù)
        • 數(shù)據(jù)集
        • 實(shí)際值
        • 估計(jì)值
      • 梯度下降算法
        • 估計(jì)誤差
        • 代價(jià)函數(shù)
        • 學(xué)習(xí)率
        • 參數(shù)更新
      • `Python`實(shí)現(xiàn)
        • 導(dǎo)包
        • 數(shù)據(jù)預(yù)處理
        • 迭代過(guò)程
        • 結(jié)果可視化
        • 完整代碼
      • 結(jié)果可視化
        • 線性擬合結(jié)果
        • 代價(jià)變化

數(shù)據(jù)

數(shù)據(jù)集

( x ( i ) , y ( i ) ) , i = 1 , 2 , ? , m \left(x^{(i)} , y^{(i)}\right) , i = 1 , 2 , \cdots , m (x(i),y(i)),i=1,2,?,m

實(shí)際值

y ( i ) y^{(i)} y(i)

估計(jì)值

h θ ( x ( i ) ) = θ 0 + θ 1 x ( i ) h_{\theta}\left(x^{(i)}\right) = \theta_{0} + \theta_{1} x^{(i)} hθ?(x(i))=θ0?+θ1?x(i)


梯度下降算法

估計(jì)誤差

h θ ( x ( i ) ) ? y ( i ) h_{\theta}\left(x^{(i)}\right) - y^{(i)} hθ?(x(i))?y(i)

代價(jià)函數(shù)

J ( θ ) = J ( θ 0 , θ 1 ) = 1 2 m ∑ i = 1 m ( h θ ( x ( i ) ) ? y ( i ) ) 2 = 1 2 m ∑ i = 1 m ( θ 0 + θ 1 x ( i ) ? y ( i ) ) 2 J(\theta) = J(\theta_{0} , \theta_{1}) = \cfrac{1}{2m} \displaystyle\sum\limits_{i = 1}^{m}{\left(h_{\theta}\left(x^{(i)}\right) - y^{(i)}\right)^{2}} = \cfrac{1}{2m} \displaystyle\sum\limits_{i = 1}^{m}{\left(\theta_{0} + \theta_{1} x^{(i)} - y^{(i)}\right)^{2}} J(θ)=J(θ0?,θ1?)=2m1?i=1m?(hθ?(x(i))?y(i))2=2m1?i=1m?(θ0?+θ1?x(i)?y(i))2

學(xué)習(xí)率
  • α \alpha α是學(xué)習(xí)率,一個(gè)大于 0 0 0的很小的經(jīng)驗(yàn)值,決定代價(jià)函數(shù)下降的程度
參數(shù)更新

Δ θ j = ? ? θ j J ( θ 0 , θ 1 ) \Delta{\theta_{j}} = \cfrac{\partial}{\partial{\theta_{j}}} J(\theta_{0} , \theta_{1}) Δθj?=?θj???J(θ0?,θ1?)

θ j : = θ j ? α Δ θ j = θ j ? α ? ? θ j J ( θ 0 , θ 1 ) \theta_{j} := \theta_{j} - \alpha \Delta{\theta_{j}} = \theta_{j} - \alpha \cfrac{\partial}{\partial{\theta_{j}}} J(\theta_{0} , \theta_{1}) θj?:=θj??αΔθj?=θj??α?θj???J(θ0?,θ1?)

$$
\left[
\begin{matrix}
\theta_{0} \
\theta_{1}
\end{matrix}
\right] :=

\left[
\begin{matrix}
\theta_{0} \
\theta_{1}
\end{matrix}
\right] -
\alpha

\left[
\begin{matrix}
\cfrac{\partial{J(\theta_{0} , \theta_{1})}}{\partial{\theta_{0}}} \
\cfrac{\partial{J(\theta_{0} , \theta_{1})}}{\partial{\theta_{1}}}
\end{matrix}
\right]
$$

[ ? J ( θ 0 , θ 1 ) ? θ 0 ? J ( θ 0 , θ 1 ) ? θ 1 ] = [ 1 m ∑ i = 1 m ( h θ ( x ( i ) ) ? y ( i ) ) 1 m ∑ i = 1 m ( h θ ( x ( i ) ) ? y ( i ) ) x ( i ) ] = [ 1 m ∑ i = 1 m e ( i ) 1 m ∑ i = 1 m e ( i ) x ( i ) ] e ( i ) = h θ ( x ( i ) ) ? y ( i ) \left[ \begin{matrix} \cfrac{\partial{J(\theta_{0} , \theta_{1})}}{\partial{\theta_{0}}} \\ \cfrac{\partial{J(\theta_{0} , \theta_{1})}}{\partial{\theta_{1}}} \end{matrix} \right] = \left[ \begin{matrix} \cfrac{1}{m} \displaystyle\sum\limits_{i = 1}^{m}{\left(h_{\theta}\left(x^{(i)}\right) - y^{(i)}\right)} \\ \cfrac{1}{m} \displaystyle\sum\limits_{i = 1}^{m}{\left(h_{\theta}\left(x^{(i)}\right) - y^{(i)}\right) x^{(i)}} \end{matrix} \right] = \left[ \begin{matrix} \cfrac{1}{m} \displaystyle\sum\limits_{i = 1}^{m}{e^{(i)}} \\ \cfrac{1}{m} \displaystyle\sum\limits_{i = 1}^{m}{e^{(i)} x^{(i)}} \end{matrix} \right] \kern{2em} e^{(i)} = h_{\theta}\left(x^{(i)}\right) - y^{(i)} ??θ0??J(θ0?,θ1?)??θ1??J(θ0?,θ1?)?? ?= ?m1?i=1m?(hθ?(x(i))?y(i))m1?i=1m?(hθ?(x(i))?y(i))x(i)? ?= ?m1?i=1m?e(i)m1?i=1m?e(i)x(i)? ?e(i)=hθ?(x(i))?y(i)

[ ? J ( θ 0 , θ 1 ) ? θ 0 ? J ( θ 0 , θ 1 ) ? θ 1 ] = [ 1 m ∑ i = 1 m e ( i ) 1 m ∑ i = 1 m e ( i ) x ( i ) ] = [ 1 m ( e ( 1 ) + e ( 2 ) + ? + e ( m ) ) 1 m ( e ( 1 ) x ( 1 ) + e ( 2 ) x ( 2 ) + ? + e ( m ) x ( m ) ) ] = 1 m [ 1 1 ? 1 x ( 1 ) x ( 2 ) ? x ( m ) ] [ e ( 1 ) e ( 2 ) ? e ( m ) ] = 1 m X T e = 1 m X T ( X θ ? y ) \begin{aligned} \left[ \begin{matrix} \cfrac{\partial{J(\theta_{0} , \theta_{1})}}{\partial{\theta_{0}}} \\ \cfrac{\partial{J(\theta_{0} , \theta_{1})}}{\partial{\theta_{1}}} \end{matrix} \right] &= \left[ \begin{matrix} \cfrac{1}{m} \displaystyle\sum\limits_{i = 1}^{m}{e^{(i)}} \\ \cfrac{1}{m} \displaystyle\sum\limits_{i = 1}^{m}{e^{(i)} x^{(i)}} \end{matrix} \right] = \left[ \begin{matrix} \cfrac{1}{m} \left(e^{(1)} + e^{(2)} + \cdots + e^{(m)}\right) \\ \cfrac{1}{m} \left(e^{(1)} x^{(1)} + e^{(2)} x^{(2)} + \cdots + e^{(m)} x^{(m)}\right) \end{matrix} \right] \\ &= \cfrac{1}{m} \left[ \begin{matrix} 1 & 1 & \cdots & 1 \\ x^{(1)} & x^{(2)} & \cdots & x^{(m)} \end{matrix} \right] \left[ \begin{matrix} e^{(1)} \\ e^{(2)} \\ \vdots \\ e^{(m)} \end{matrix} \right] = \cfrac{1}{m} X^{T} e = \cfrac{1}{m} X^{T} (X \theta - y) \end{aligned} ??θ0??J(θ0?,θ1?)??θ1??J(θ0?,θ1?)?? ??= ?m1?i=1m?e(i)m1?i=1m?e(i)x(i)? ?= ?m1?(e(1)+e(2)+?+e(m))m1?(e(1)x(1)+e(2)x(2)+?+e(m)x(m))? ?=m1?[1x(1)?1x(2)????1x(m)?] ?e(1)e(2)?e(m)? ?=m1?XTe=m1?XT(?y)?

  • 由上述推導(dǎo)得

Δ θ = 1 m X T e \Delta{\theta} = \cfrac{1}{m} X^{T} e Δθ=m1?XTe

θ : = θ ? α Δ θ = θ ? α 1 m X T e \theta := \theta - \alpha \Delta{\theta} = \theta - \alpha \cfrac{1}{m} X^{T} e θ:=θ?αΔθ=θ?αm1?XTe


Python實(shí)現(xiàn)

導(dǎo)包
import numpy as np
import matplotlib.pyplot as plt
數(shù)據(jù)預(yù)處理
x = np.array([4, 3, 3, 4, 2, 2, 0, 1, 2, 5, 1, 2, 5, 1, 3])
y = np.array([8, 6, 6, 7, 4, 4, 2, 4, 5, 9, 3, 4, 8, 3, 6])m = len(x)x = np.c_[np.ones((m, 1)), x]
y = y.reshape(m, 1)
迭代過(guò)程
alpha = 0.01  # 學(xué)習(xí)率
iter_cnt = 1000  # 迭代次數(shù)
cost = np.zeros(iter_cnt)  # 代價(jià)數(shù)據(jù)
theta = np.zeros((2, 1))for i in range(iter_cnt):h = x.dot(theta)  # 估計(jì)值error = h - y  # 誤差值cost[i] = 1 / (2 * m) * error.T.dot(error)  # 代價(jià)值# cost[i] = 1 / (2 * m) * np.sum(np.square(error))  # 代價(jià)值# 更新參數(shù)delta_theta = 1 / m * x.T.dot(error)theta -= alpha * delta_theta
結(jié)果可視化
# 線性擬合結(jié)果
plt.scatter(x[:, 1], y, c='blue')
plt.plot(x[:, 1], h, 'r-')
plt.savefig('../pic/fit.png')
plt.show()# 代價(jià)結(jié)果
plt.plot(cost)
plt.savefig('../pic/cost.png')
plt.show()
完整代碼
import numpy as np
import matplotlib.pyplot as pltx = np.array([4, 3, 3, 4, 2, 2, 0, 1, 2, 5, 1, 2, 5, 1, 3])
y = np.array([8, 6, 6, 7, 4, 4, 2, 4, 5, 9, 3, 4, 8, 3, 6])m = len(x)x = np.c_[np.ones((m, 1)), x]
y = y.reshape(m, 1)alpha = 0.01  # 學(xué)習(xí)率
iter_cnt = 1000  # 迭代次數(shù)
cost = np.zeros(iter_cnt)  # 代價(jià)數(shù)據(jù)
theta = np.zeros((2, 1))for i in range(iter_cnt):h = x.dot(theta)  # 估計(jì)值error = h - y  # 誤差值cost[i] = 1 / (2 * m) * error.T.dot(error)  # 代價(jià)值# cost[i] = 1 / (2 * m) * np.sum(np.square(error))  # 代價(jià)值# 更新參數(shù)delta_theta = 1 / m * x.T.dot(error)theta -= alpha * delta_theta# 線性擬合結(jié)果
plt.scatter(x[:, 1], y, c='blue')
plt.plot(x[:, 1], h, 'r-')
plt.savefig('../pic/fit.png')
plt.show()# 代價(jià)結(jié)果
plt.plot(cost)
plt.savefig('../pic/cost.png')
plt.show()

結(jié)果可視化

線性擬合結(jié)果

1

代價(jià)變化

2


http://aloenet.com.cn/news/32552.html

相關(guān)文章:

  • 幫彩票網(wǎng)站做流量提升seo賺錢方式
  • 東莞網(wǎng)站建設(shè) 環(huán)保設(shè)備自創(chuàng)網(wǎng)站
  • 武漢建站中心百度廣告競(jìng)價(jià)排名
  • 淘客網(wǎng)站要怎么做黑帽seo技巧
  • 政府網(wǎng)站建設(shè)事例常見的推廣方式有哪些
  • 遼河油田建設(shè)有限公司網(wǎng)站找個(gè)網(wǎng)站
  • 9420高清免費(fèi)視頻在線觀看武漢抖音seo搜索
  • 做網(wǎng)站需要懂什么廣州網(wǎng)頁(yè)定制多少錢
  • 做怎么樣的網(wǎng)站好如何自己弄個(gè)免費(fèi)網(wǎng)站
  • 怎么做一元購(gòu)網(wǎng)站代運(yùn)營(yíng)公司哪家好一些
  • 做網(wǎng)站靠教育賺錢seo的基礎(chǔ)優(yōu)化
  • com是什么網(wǎng)站廣告推廣策劃
  • 我的世界做披風(fēng)網(wǎng)站友情鏈接檢測(cè)的特點(diǎn)
  • 松原網(wǎng)站制作如何讓百度收錄自己的網(wǎng)站
  • 婁底網(wǎng)站建設(shè)的話術(shù)北京seo運(yùn)營(yíng)推廣
  • 網(wǎng)站建設(shè)基礎(chǔ)大綱文案軟文推廣有哪些
  • 網(wǎng)站開發(fā)用的那些語(yǔ)言怎么在百度發(fā)布自己的文章
  • 花店網(wǎng)站建設(shè)環(huán)境分析百度搜索什么關(guān)鍵詞能搜到網(wǎng)站
  • 午夜做網(wǎng)站營(yíng)銷網(wǎng)站的宣傳、推廣與運(yùn)作
  • 淘寶站內(nèi)推廣方式有哪些班級(jí)優(yōu)化大師使用心得
  • 許昌做網(wǎng)站漢獅網(wǎng)絡(luò)青島seo關(guān)鍵詞優(yōu)化公司
  • 網(wǎng)上建站賺錢微信公眾號(hào)推廣軟文案例
  • 西安微信公眾號(hào)制作seo優(yōu)化快速排名
  • 網(wǎng)站建設(shè) 中國(guó)聯(lián)盟網(wǎng)百度網(wǎng)頁(yè)版登錄首頁(yè)
  • 怎么把網(wǎng)站提交百度的推廣廣告
  • 模板企業(yè)快速建站關(guān)鍵詞推廣效果分析
  • 青島商業(yè)網(wǎng)站建設(shè)今日油價(jià)92汽油
  • 韓國(guó)網(wǎng)站設(shè)計(jì)風(fēng)格cctv 13新聞?lì)l道
  • 800元做網(wǎng)站哪里做網(wǎng)絡(luò)推廣
  • wordpress所有頁(yè)面溫州網(wǎng)站建設(shè)優(yōu)化