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

新闻网站寄生虫怎么做怎么创建一个网页

新闻网站寄生虫怎么做,怎么创建一个网页,上海材料网站建设,wordpress的seo文章目录 [toc]数据数据集实际值估计值 梯度下降算法估计误差代价函数学习率参数更新 Python实现导包数据预处理迭代过程结果可视化完整代码 结果可视化线性拟合结果代价变化 数据 数据集 ( x ( i ) , y ( i ) ) , i 1 , 2 , ⋯ , m \left(x^{(i)} , y^{(i)}\right) , i 1 ,…

文章目录

    • @[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)

$$
\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)} θ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 ) 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} θ0J(θ0,θ1)θ1J(θ0,θ1) = m1i=1me(i)m1i=1me(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) =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)
迭代过程
alpha = 0.01  # 学习率
iter_cnt = 1000  # 迭代次数
cost = np.zeros(iter_cnt)  # 代价数据
theta = np.zeros((2, 1))for i in range(iter_cnt):h = x.dot(theta)  # 估计值error = h - y  # 误差值cost[i] = 1 / (2 * m) * error.T.dot(error)  # 代价值# cost[i] = 1 / (2 * m) * np.sum(np.square(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.savefig('../pic/fit.png')
plt.show()# 代价结果
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  # 学习率
iter_cnt = 1000  # 迭代次数
cost = np.zeros(iter_cnt)  # 代价数据
theta = np.zeros((2, 1))for i in range(iter_cnt):h = x.dot(theta)  # 估计值error = h - y  # 误差值cost[i] = 1 / (2 * m) * error.T.dot(error)  # 代价值# cost[i] = 1 / (2 * m) * np.sum(np.square(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.savefig('../pic/fit.png')
plt.show()# 代价结果
plt.plot(cost)
plt.savefig('../pic/cost.png')
plt.show()

结果可视化

线性拟合结果

1

代价变化

2


http://www.yidumall.com/news/49098.html

相关文章:

  • php网站数据迁移郑州网站营销推广
  • 企业网站建设立项报告google移动服务应用优化
  • 网站中的轮播怎么做百度账号申诉
  • 网站不换域名换空间2022搜索引擎
  • 广州专业的网站建设汕头seo外包公司
  • 网站建设跑业务发布新闻
  • 哪个外贸网站开发客户比较好用石家庄今天最新新闻头条
  • 老年夫妻做爰视频网站seo搜索引擎优化排名报价
  • 网站建设推广关键词软文兼职10元一篇
  • 微网站可以自己做吗搜索引擎优化排名seo
  • 有了页游源代码如何做网站怎么申请域名建网站
  • 网站登陆界面psd广州百度搜索优化
  • 网站开发后台编辑系统简述seo和sem的区别与联系
  • 苏州网站推杭州今天查出多少阳性
  • jsp商务网站开发济南网站推广优化
  • 平面设计软件学哪个比较好站长工具seo综合查询引流
  • 如何看那个网站是那个公司做的建设优化网站
  • 外贸网络推广网惠州百度推广优化排名
  • 东莞长城开发科技有限公司seo课程心得体会
  • 动态网页设计课程设计报告旺道seo怎么优化网站
  • 集团有限公司成立条件公司网站seo公司
  • 上海网站编辑招聘比较好的软文发布平台
  • 株洲做网站优化网站地址ip域名查询
  • 学做网站用什么软件武汉千锋教育培训机构怎么样
  • 哪个网站能帮助做试卷四川百度推广和seo优化
  • express做静态网站怎么推广一个平台
  • 网站建设公司模版网络广告人社区
  • 建设单位经常去哪个网站如何制作一个自己的网页网站
  • 外贸饰品网站微平台推广
  • 泰安网签数据淄博seo公司