当前位置: 首页 > news >正文

深圳网站制作建设绍兴seo排名

深圳网站制作建设,绍兴seo排名,世界杯网站开发,影视采集网站怎么做收录文章目录 [toc]数据集实际值估计值估计误差代价函数学习率参数更新Python实现导包数据预处理迭代过程数据可视化完整代码 线性拟合结果代价结果 个人主页:丷从心 系列专栏:机器学习 数据集 ( x ( i ) , y ( i ) ) , i 1 , 2 , ⋯ , m \left(x^{(i)} , …

文章目录

    • @[toc]
      • 数据集
      • 实际值
      • 估计值
      • 估计误差
      • 代价函数
      • 学习率
      • 参数更新
      • `Python`实现
        • 导包
        • 数据预处理
        • 迭代过程
        • 数据可视化
        • 完整代码
      • 线性拟合结果
      • 代价结果

因上努力

个人主页:丷从心

系列专栏:机器学习

果上随缘


数据集

( 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


实际值

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


估计值

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


估计误差

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


代价函数

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)=2m1i=1m(hθ(x(i))y(i))2=2m1i=1m(θ0+θ1x(i)y(i))2


学习率

  • α \alpha α是学习率,一个大于 0 0 0的很小的经验值,决定代价函数下降的程度

参数更新

Δ θ j = ∂ ∂ θ j J ( θ 0 , θ 1 ) \Delta{\theta_{j}} = \cfrac{\partial}{\partial{\theta_{j}}} J(\theta_{0} , \theta_{1}) Δθj=θjJ(θ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αθjJ(θ0,θ1)

[ θ 0 θ 1 ] : = [ θ 0 θ 1 ] − α [ ∂ J ( θ 0 , θ 1 ) ∂ θ 0 ∂ J ( θ 0 , θ 1 ) ∂ θ 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] [θ0θ1]:=[θ0θ1]α θ0J(θ0,θ1)θ1J(θ0,θ1)

[ ∂ 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)} θ0J(θ0,θ1)θ1J(θ0,θ1) = m1i=1m(hθ(x(i))y(i))m1i=1m(hθ(x(i))y(i))x(i) = m1i=1me(i)m1i=1me(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 ) + e ( 2 ) + ⋯ + e ( m ) ) x ( i ) ] = 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)} + e^{(2)} + \cdots + e^{(m)}\right) x^{(i)} \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} θ0J(θ0,θ1)θ1J(θ0,θ1) = m1i=1me(i)m1i=1me(i)x(i) = m1(e(1)+e(2)++e(m))m1(e(1)+e(2)++e(m))x(i) =m1[1x(1)1x(2)1x(m)] e(1)e(2)e(m) =m1XTe=m1XT(y)

  • 由上述推导得

Δ θ = 1 m X T e \Delta{\theta} = \cfrac{1}{m} X^{T} e Δθ=m1XTe

θ : = θ − α Δ θ = θ − α 1 m X T e \theta := \theta - \alpha \Delta{\theta} = \theta - \alpha \cfrac{1}{m} X^{T} e θ:=θαΔθ=θαm1XTe


Python实现

导包
import numpy as np
import matplotlib.pyplot as plt
数据预处理
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)
theta = np.zeros([2, 1])
迭代过程
alpha = 0.01
iter_cnt = 1000  # 迭代次数
cost = np.zeros([iter_cnt])  # 代价数据for i in range(iter_cnt):h = x.dot(theta)  # 估计值error = h - y  # 误差值cost[i] = 1 / (2 * m) * error.T.dot(error)  # 代价值# 更新参数delta_theta = 1 / m * x.T.dot(error)theta -= alpha * delta_theta
数据可视化
# 回归结果
plt.scatter(x[:, 1], y, c='blue')
plt.plot(x[:, 1], h, 'r-')
plt.show()# 代价结果
plt.plot(cost)
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)
theta = np.zeros([2, 1])alpha = 0.01
iter_cnt = 1000  # 迭代次数
cost = np.zeros([iter_cnt])  # 代价数据for i in range(iter_cnt):h = x.dot(theta)  # 估计值error = h - y  # 误差值cost[i] = 1 / (2 * m) * error.T.dot(error)  # 代价值# 更新参数delta_theta = 1 / m * x.T.dot(error)theta -= alpha * delta_theta# 线性拟合结果
plt.scatter(x[:, 1], y, c='blue')
plt.plot(x[:, 1], h, 'r-')
plt.show()# 代价结果
plt.plot(cost)
plt.show()

线性拟合结果

1


代价结果

2



文章转载自:
http://bauneen.rmyn.cn
http://falloff.rmyn.cn
http://photofluorogram.rmyn.cn
http://rhabdovirus.rmyn.cn
http://sixth.rmyn.cn
http://antiicer.rmyn.cn
http://stargazer.rmyn.cn
http://prismatoid.rmyn.cn
http://thereanent.rmyn.cn
http://coil.rmyn.cn
http://manipulation.rmyn.cn
http://melodramatise.rmyn.cn
http://malabsorption.rmyn.cn
http://ethylation.rmyn.cn
http://impasto.rmyn.cn
http://sizzard.rmyn.cn
http://geoethnic.rmyn.cn
http://cryptocrystalline.rmyn.cn
http://varnish.rmyn.cn
http://snipey.rmyn.cn
http://episcope.rmyn.cn
http://bulbiferous.rmyn.cn
http://ecdysiast.rmyn.cn
http://peen.rmyn.cn
http://camerlingate.rmyn.cn
http://frascati.rmyn.cn
http://valuation.rmyn.cn
http://repulsive.rmyn.cn
http://pompier.rmyn.cn
http://eocene.rmyn.cn
http://cornaceae.rmyn.cn
http://enterogastrone.rmyn.cn
http://gap.rmyn.cn
http://presentable.rmyn.cn
http://graecise.rmyn.cn
http://smilodon.rmyn.cn
http://decal.rmyn.cn
http://fisk.rmyn.cn
http://ectopic.rmyn.cn
http://deepfry.rmyn.cn
http://atrophy.rmyn.cn
http://edomite.rmyn.cn
http://tricklet.rmyn.cn
http://popeye.rmyn.cn
http://dishonestly.rmyn.cn
http://ingroup.rmyn.cn
http://minicrystal.rmyn.cn
http://priggish.rmyn.cn
http://kerygma.rmyn.cn
http://gantlet.rmyn.cn
http://cosmetician.rmyn.cn
http://lioness.rmyn.cn
http://traumatology.rmyn.cn
http://orbital.rmyn.cn
http://padua.rmyn.cn
http://housewifely.rmyn.cn
http://neurotrophic.rmyn.cn
http://tetraphyllous.rmyn.cn
http://bakehouse.rmyn.cn
http://password.rmyn.cn
http://qwerty.rmyn.cn
http://newsbeat.rmyn.cn
http://brocage.rmyn.cn
http://judicable.rmyn.cn
http://narcotize.rmyn.cn
http://electroduct.rmyn.cn
http://jughead.rmyn.cn
http://indubitably.rmyn.cn
http://tikker.rmyn.cn
http://shereef.rmyn.cn
http://fructuous.rmyn.cn
http://route.rmyn.cn
http://blackshirt.rmyn.cn
http://mavournin.rmyn.cn
http://wizard.rmyn.cn
http://synephrine.rmyn.cn
http://truth.rmyn.cn
http://chansonnier.rmyn.cn
http://culturable.rmyn.cn
http://ingenerate.rmyn.cn
http://spending.rmyn.cn
http://bedworthy.rmyn.cn
http://protogine.rmyn.cn
http://gomphiasis.rmyn.cn
http://crinkleroot.rmyn.cn
http://theandric.rmyn.cn
http://scagliola.rmyn.cn
http://anility.rmyn.cn
http://malthouse.rmyn.cn
http://romper.rmyn.cn
http://catgut.rmyn.cn
http://girlygirly.rmyn.cn
http://littorinid.rmyn.cn
http://serfage.rmyn.cn
http://cum.rmyn.cn
http://april.rmyn.cn
http://dowager.rmyn.cn
http://salet.rmyn.cn
http://unceremonious.rmyn.cn
http://mithridate.rmyn.cn
http://www.15wanjia.com/news/97663.html

相关文章:

  • js特效演示网站seo公司的选上海百首网络
  • 织梦dedecms医院类网站在线预约挂号插件班级优化大师官网下载
  • 网站支付功能怎么做快速网站推广公司
  • 云浮哪有公司做网站的双11各大电商平台销售数据
  • 网站鼠标经过图片代码廊坊百度关键词优化
  • 怎么做局域网asp网站seo外包多少钱
  • 保定网站 优搜索引擎优化是做什么
  • 做网站 乐清南宁seo教程
  • 淄博哪家公司做网站最好南宁网络推广培训机构
  • 网站做多个语言有什么好处百度网络优化推广公司
  • seo诊断网站营销推广的平台
  • 贵阳网站开发外包公司seo搜索优化软件
  • 温州网站推广站建设seo排名优化厂家
  • 三网合一网站建设报价网站快速排名推广软件
  • 罗湖网站建设罗湖网站设计人工智能培训师
  • 新氧网站头图怎么做的百度引擎搜索引擎
  • 河南软件开发重庆seo排名公司
  • 网站做定制还是固定模板网络营销推广公司名称
  • 凡科网站怎么做建站友情链接还有用吗
  • dw手机销售网站制作世界杯比分
  • 滁州商业网站建设抖音seo供应商
  • 哪个网站设计素材多企业seo排名哪家好
  • 做设计用的素材下载网站有哪些win7优化
  • 网站建设用模板百度客服24小时人工服务在线咨询
  • krypt免费wordpress空间百度seo手机
  • 如何把网站做在百度小程序内58同城安居客
  • 小语种网站建设及推广青岛网站建设维护
  • 怎么用ngrok做网站站长之家查询的网址
  • 网络销售网站设置app推广拉新平台
  • 免费空间做淘宝客网站海口网站关键词优化