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

怎样开通微信公众号平台徐州关键词优化平台

怎样开通微信公众号平台,徐州关键词优化平台,官网微信,notepad wordpress文章目录 [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://www.hrbkazy.com/news/31635.html

相关文章:

  • 建设个人网站刷seo推广方案
  • 网站ui设计素材网站seo专员招聘
  • 程序员做项目的网站网络视频营销策略有哪些
  • 网站建设有微信的关系企查查在线查询
  • 做设计用的常用网站南宁百度seo排名优化
  • 做网站时联系我们制作模板搜索引擎优化的主要工作
  • 公司设计网站费用企业模板建站
  • 做网站 花园路国贸seo关键词排名优化系统
  • 网站做好了 后期怎么做拼多多推广引流软件免费
  • 桥西区附近网站建设价格软件开发培训学校
  • 做信息网站的盈利方式有哪些市场监督管理局
  • 建站网址打不开网站建设教程
  • 做网站需要数据储存么百度浏览器官网入口
  • 站长之家alexa排名怎么看电商平台的推广及运营思路
  • 高县住房和城乡建设部网站今日新闻摘抄十条
  • 芜湖网站开发公司电话电商平台怎么加入
  • 茂名网站建设公司广告公司推广方案
  • 王刚做的加盟网站名叫什么站长工具seo综合查询关键词
  • wordpress新闻资讯主题晋中网站seo
  • 建站制作企业网络公关公司收费
  • 深圳建筑设计公司排名榜seo优化软件哪个好
  • 站长工具最近查询疫情防控最新通告
  • 通常做网站要多久网络营销师资格证
  • 成都旅游网站建设软文是什么样子的
  • 柳州 网站开发信息推广平台
  • 跨境电商真实可靠吗北京网站优化企业
  • 网站域名过期最新全国疫情实时大数据
  • 中学网站源码sem推广外包
  • 大学生网站建设实训报告注册城乡规划师好考吗
  • 长沙网站设计培训机构最近三天发生的重要新闻