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

wordpress地址和站点地址有什么用重庆高端网站seo

wordpress地址和站点地址有什么用,重庆高端网站seo,计算机网络技术网站建设方向,网站改版 翻译正规方程求解线性回归 首先正规方程如下: Θ ( X T X ) − 1 X T y \begin{equation} \Theta (X^T X)^{-1} X^T y \end{equation} Θ(XTX)−1XTy​​ 接下来通过线性代数的角度理解这个问题。 二维空间 在二维空间上,有两个向量 a a a和 b b b&…

正规方程求解线性回归

首先正规方程如下:
Θ = ( X T X ) − 1 X T y \begin{equation} \Theta = (X^T X)^{-1} X^T y \end{equation} Θ=(XTX)1XTy
接下来通过线性代数的角度理解这个问题。

二维空间

在二维空间上,有两个向量 a a a b b b,若 b b b投影到 a a a要怎么做,很简单,做垂线, 那么投影后的向量记为 p p p,那么 b b b p p p之间的error记为 e = b − p e=b-p e=bp。同时 p p p a a a上,所以 p p p一定是 a a a x x x(标量)倍,记为 p = x a p=xa p=xa。因为 e e e垂直 a a a,所以 a T ( b − x a ) = 0 a^T(b-xa)=0 aT(bxa)=0 ,即 x a T a = a T b xa^Ta=a^Tb xaTa=aTb,得到
x = a T b a T a x=\frac{a^Tb}{a^Ta} x=aTaaTb
那么
p = x a = a a T b a T a p=xa=a\frac{a^Tb}{a^Ta} p=xa=aaTaaTb
根据上面的公式,如果 a a a翻倍了,那么投影不变,如果 b b b翻倍了,投影也翻倍。投影是由一个矩阵 P P P完成的, p = P b p=Pb p=Pb,那么投影矩阵 P P P
P = a a T a T a P=\frac{aa^T}{a^Ta} P=aTaaaT
用任何向量乘这个投影矩阵,你总会变换到它的列空间中。同时显然有: P T = P P^T=P PT=P , P 2 = P P^2=P P2=P,即投影两次的结果还是和第一次一样。

高维空间

为什么要做投影呢?

因为, A x = b Ax=b Ax=b可能无解,比如一堆等式,比未知数还多,就可能造成无解。那么该怎么办,只能求解最接近的哪个可能解,哪个才是最接近的呢?问题是 A x Ax Ax总是在 A A A的列空间中,而 b b b不一定在。所以要怎么微调 b b b将它变为列空间中最接近它的那一个,那么就将问题换作求解,有解的 A x ^ = p A\hat{x}=p Ax^=p。所以得找最好的那个投影 p p p,以最好的接近 b b b,这就是为什么要引入投影的原因了。

那么我们来看高维空间,这里以三维空间举例,自然可以推广到n维空间。

现在有一个不在平面上的 b b b向量,想要将 b b b投影在平面上,平面可以由两个基向量 a 1 a_1 a1 a 2 a_2 a2表示。同样的 b b b投影到平面上的误差记为 e = b − p e=b-p e=bp,这个 e e e是垂直平面的。 p = x 1 ^ a 1 + x 2 ^ a 2 = A x ^ p=\hat{x_1}a_1+\hat{x_2}a_2=A\hat{x} p=x1^a1+x2^a2=Ax^,我们想要解出 x ^ \hat{x} x^。因为 e e e是垂直平面,所以有 b − A x ^ b-A\hat{x} bAx^垂直平面,即有 a 1 T ( b − A x ^ ) = 0 a_1^T(b-A\hat{x})=0 a1T(bAx^)=0, a 2 T ( b − A x ^ ) = 0 a_2^T(b-A\hat{x})=0 a2T(bAx^)=0,表示为矩阵乘法便有
A T ( b − A x ^ ) = A e = 0 A^T(b-A\hat{x})=Ae=0 AT(bAx^)=Ae=0
这个形式与二维空间的很像吧。对于 A e = 0 Ae=0 Ae=0,可知 e e e位于 A T A^T AT的零空间,也就是说 e e e垂直于于 A A A的列空间。由上面式子可得
A T A x ^ = A T b A^TA\hat{x}=A^Tb ATAx^=ATb
继而
x ^ = ( A T A ) − 1 A T b \hat{x}=(A^TA)^{-1}A^Tb x^=(ATA)1ATb
这不就是我们的正规方程吗。到这里我们的正规方程便推导出来了,但为了内容完整,我们下面收个尾。
p = A x ^ = A ( A T A ) − 1 A T b P = A ( A T A ) − 1 A T P T = P P 2 = P p=A\hat{x}=A(A^TA)^{-1}A^Tb \\ P=A(A^TA)^{-1}A^T\\ P^T=P\\ P^2=P p=Ax^=A(ATA)1ATbP=A(ATA)1ATPT=PP2=P
这些结论还是和二维空间上的一样, P T = P P^T=P PT=P , P 2 = P P^2=P P2=P,即投影两次的结果还是和第一次一样。

最小二乘法

正规方程的一个常见应用例子是最小二乘法。从线性代数的角度来看,正规方程是通过最小二乘法求解线性回归问题的一种方法。以下是正规方程的概述:

1. 模型表示

在线性回归中,我们假设目标变量 y y y 与特征矩阵 X X X 之间存在线性关系:

y ^ = X θ \hat{y} = X \theta y^=

其中:

  • y ^ \hat{y} y^ 是预测值(一个 m m m 维列向量)。
  • X X X 是特征矩阵( m × n m \times n m×n),每行代表一个样本,每列代表一个特征。
  • θ \theta θ 是模型参数(权重向量)。

2. 目标函数

我们的目标是最小化预测值与实际值之间的误差,通常使用残差平方和:

J ( θ ) = ∥ y − X θ ∥ 2 J(\theta) = \|y - X\theta\|^2 J(θ)=y2

3. 求解过程

为了找到使得 J ( θ ) J(\theta) J(θ) 最小的 θ \theta θ,我们可以通过对 J ( θ ) J(\theta) J(θ) 关于 θ \theta θ 的导数求解,设导数为零:

∇ J ( θ ) = − 2 X T ( y − X θ ) = 0 \nabla J(\theta) = -2X^T(y - X\theta) = 0 J(θ)=2XT(y)=0

展开后得到:

X T X θ = X T y X^T X \theta = X^T y XT=XTy

4. 正规方程

这个方程称为正规方程,其形式为:

X T X θ = X T y X^T X \theta = X^T y XT=XTy

5. 解的唯一性

  • X T X X^T X XTX 是可逆的(即列向量线性无关),则可以通过求逆得到参数的解:

θ = ( X T X ) − 1 X T y \theta = (X^T X)^{-1} X^T y θ=(XTX)1XTy

  • 如果 X T X X^T X XTX 不可逆(即存在多重共线性),则正规方程可能没有唯一解。

6. 几何解释

从几何的角度,正规方程可以被视为在特征空间中寻找一个超平面,使得目标变量 y y y 的投影与预测值 X θ X \theta 之间的误差最小化。

总结

正规方程通过线性代数的方法为线性回归提供了解的表达式,使得我们可以有效地计算参数。其核心思想是通过最小化残差平方和,寻找最佳拟合的线性模型。


梯度下降求解线性回归

import numpy as np
def linear_regression_gradient_descent(X: np.ndarray, y: np.ndarray, alpha: float, iterations: int) -> np.ndarray:m, n = X.shapetheta = np.zeros((n, 1))for _ in range(iterations):predictions = X @ thetaerrors = predictions - y.reshape(-1, 1)updates = X.T @ errors / mtheta -= alpha * updatesreturn np.round(theta.flatten(), 4)

其他都好理解,下面主要讲梯度updates的推导

1. 定义损失函数

线性回归的损失函数通常是均方误差(Mean Squared Error, MSE):

MSE = 1 2 m ∑ i = 1 m ( h θ ( x ( i ) ) − y ( i ) ) 2 \text{MSE} = \frac{1}{2m} \sum_{i=1}^{m} (h_\theta(x^{(i)}) - y^{(i)})^2 MSE=2m1i=1m(hθ(x(i))y(i))2

这里, h θ ( x ( i ) ) = X ( i ) ⋅ θ h_\theta(x^{(i)}) = X^{(i)} \cdot \theta hθ(x(i))=X(i)θ 是模型的预测值, y ( i ) y^{(i)} y(i) 是实际值。

2. 对损失函数求导

为了最小化损失函数,我们需要对参数 θ \theta θ 求导:

∂ MSE ∂ θ = ∂ ∂ θ ( 1 2 m ∑ i = 1 m ( h θ ( x ( i ) ) − y ( i ) ) 2 ) \frac{\partial \text{MSE}}{\partial \theta} = \frac{\partial}{\partial \theta} \left( \frac{1}{2m} \sum_{i=1}^{m} (h_\theta(x^{(i)}) - y^{(i)})^2 \right) θMSE=θ(2m1i=1m(hθ(x(i))y(i))2)

应用链式法则,首先求导内部的平方项:

∂ ∂ θ ( h θ ( x ( i ) ) − y ( i ) ) 2 = 2 ( h θ ( x ( i ) ) − y ( i ) ) ⋅ ∂ h θ ( x ( i ) ) ∂ θ \frac{\partial}{\partial \theta} (h_\theta(x^{(i)}) - y^{(i)})^2 = 2(h_\theta(x^{(i)}) - y^{(i)}) \cdot \frac{\partial h_\theta(x^{(i)})}{\partial \theta} θ(hθ(x(i))y(i))2=2(hθ(x(i))y(i))θhθ(x(i))

而且 h θ ( x ( i ) ) = X ( i ) ⋅ θ h_\theta(x^{(i)}) = X^{(i)} \cdot \theta hθ(x(i))=X(i)θ,所以:

∂ h θ ( x ( i ) ) ∂ θ = X ( i ) \frac{\partial h_\theta(x^{(i)})}{\partial \theta} = X^{(i)} θhθ(x(i))=X(i)

将这个结果代入:

∂ MSE ∂ θ = 1 m ∑ i = 1 m ( h θ ( x ( i ) ) − y ( i ) ) X ( i ) \frac{\partial \text{MSE}}{\partial \theta} = \frac{1}{m} \sum_{i=1}^{m} (h_\theta(x^{(i)}) - y^{(i)}) X^{(i)} θMSE=m1i=1m(hθ(x(i))y(i))X(i)

3. 用向量表示

将上述和式转换为向量形式。定义误差向量:

errors = predictions − y \text{errors} = \text{predictions} - y errors=predictionsy

其中 predictions = X ⋅ θ \text{predictions} = X \cdot \theta predictions=Xθ。这样,梯度可以表示为:

gradient = 1 m ( X T ⋅ errors ) \text{gradient} = \frac{1}{m} (X^T \cdot \text{errors}) gradient=m1(XTerrors)

4. 结论

因此,梯度的计算公式来源于损失函数的求导过程,通过向量化的方式将每个样本的误差与特征相乘,得出对每个参数的影响。这是梯度下降法中更新参数的基础。


文章转载自:
http://dinncochaparral.tqpr.cn
http://dinncoquadrantal.tqpr.cn
http://dinncomargot.tqpr.cn
http://dinncodibasic.tqpr.cn
http://dinncohrvatska.tqpr.cn
http://dinncobelieve.tqpr.cn
http://dinncotibetan.tqpr.cn
http://dinncounlawful.tqpr.cn
http://dinncofoozle.tqpr.cn
http://dinncofitly.tqpr.cn
http://dinncooverspeed.tqpr.cn
http://dinncodumpage.tqpr.cn
http://dinncoeucharist.tqpr.cn
http://dinncointransigency.tqpr.cn
http://dinncogilolo.tqpr.cn
http://dinncometallurgy.tqpr.cn
http://dinncocliffy.tqpr.cn
http://dinncosalus.tqpr.cn
http://dinncolorelei.tqpr.cn
http://dinncosoot.tqpr.cn
http://dinncomantua.tqpr.cn
http://dinncopalpability.tqpr.cn
http://dinncoveda.tqpr.cn
http://dinncoexpunction.tqpr.cn
http://dinncosubdwarf.tqpr.cn
http://dinncoemblem.tqpr.cn
http://dinncocathartic.tqpr.cn
http://dinncoedt.tqpr.cn
http://dinncosandboy.tqpr.cn
http://dinncofrig.tqpr.cn
http://dinncoogre.tqpr.cn
http://dinncoextravaganza.tqpr.cn
http://dinncoamphitrichous.tqpr.cn
http://dinncolampas.tqpr.cn
http://dinncosulphurous.tqpr.cn
http://dinncocalamus.tqpr.cn
http://dinncophysiographical.tqpr.cn
http://dinncobritish.tqpr.cn
http://dinncounmirthful.tqpr.cn
http://dinncoriverhead.tqpr.cn
http://dinncoparticularization.tqpr.cn
http://dinncooctothorp.tqpr.cn
http://dinncobalefulness.tqpr.cn
http://dinncoimposthume.tqpr.cn
http://dinncoderegulation.tqpr.cn
http://dinncobaseburner.tqpr.cn
http://dinncoshammer.tqpr.cn
http://dinncocineangiography.tqpr.cn
http://dinncokinsfolk.tqpr.cn
http://dinncorheumatic.tqpr.cn
http://dinncosemon.tqpr.cn
http://dinncoconsequential.tqpr.cn
http://dinncoarboricultural.tqpr.cn
http://dinncononrestrictive.tqpr.cn
http://dinncoyardmaster.tqpr.cn
http://dinncooverladen.tqpr.cn
http://dinncodigs.tqpr.cn
http://dinncouniversal.tqpr.cn
http://dinncoclannish.tqpr.cn
http://dinncowonderland.tqpr.cn
http://dinncobabs.tqpr.cn
http://dinncochickadee.tqpr.cn
http://dinncoaccessorily.tqpr.cn
http://dinncoharness.tqpr.cn
http://dinncohayward.tqpr.cn
http://dinncofourteenth.tqpr.cn
http://dinncorebuff.tqpr.cn
http://dinncodarnel.tqpr.cn
http://dinncodeontology.tqpr.cn
http://dinncocathecticize.tqpr.cn
http://dinncopolemically.tqpr.cn
http://dinncoautoplasty.tqpr.cn
http://dinncomooneye.tqpr.cn
http://dinncoelaeometer.tqpr.cn
http://dinncoeversible.tqpr.cn
http://dinnconiff.tqpr.cn
http://dinnconeoisolationism.tqpr.cn
http://dinncogormandize.tqpr.cn
http://dinncosamian.tqpr.cn
http://dinncoropiness.tqpr.cn
http://dinncoprevent.tqpr.cn
http://dinncocontrition.tqpr.cn
http://dinncoblanketry.tqpr.cn
http://dinncomiriness.tqpr.cn
http://dinncobudgerigar.tqpr.cn
http://dinncovitality.tqpr.cn
http://dinncowinebibber.tqpr.cn
http://dinncoavocation.tqpr.cn
http://dinncoglamor.tqpr.cn
http://dinncobeatlemania.tqpr.cn
http://dinncofifth.tqpr.cn
http://dinncobumiputraization.tqpr.cn
http://dinncormb.tqpr.cn
http://dinncosancta.tqpr.cn
http://dinncounhurried.tqpr.cn
http://dinncountired.tqpr.cn
http://dinncobefriend.tqpr.cn
http://dinncoentomogenous.tqpr.cn
http://dinncophotosurface.tqpr.cn
http://dinncoprecession.tqpr.cn
http://www.dinnco.com/news/136925.html

相关文章:

  • 在哪里建网站好百度关键词优化多少钱一年
  • 网站设计需要什么证深圳google推广
  • 中国建设银行app官网杭州网站优化培训
  • 关于党的网页设计江苏企业seo推广
  • 西昌有哪些做网站的公司响应式模版移动优化
  • 广告推广图片seo关键字排名
  • 最新政府网站建设理念广告设计自学教程
  • 有没有专门做艺术的网站下载优化大师并安装
  • 电商网站营销方案企业官网定制设计
  • 网站建设代码怎么导入图片国内专业seo公司
  • 泉州刺桐古建筑公司网站酒店营销推广方案
  • 南京网站制作有限公司东莞网络优化调查公司
  • 服装购物商城网站建设抖来查关键词搜索排名
  • 百度58同城找工作重庆白云seo整站优化
  • wordpress3.5搜索引擎优化方法总结
  • 一键创建网站百度网站链接提交
  • 枣强网站建设公司网络营销推广服务
  • 银行网站建设百度收录网站链接入口
  • 网站建设高端中国十大搜索引擎排名
  • 什么网站可以做图赚钱一份完整的活动策划方案
  • 网站同步到新浪微博怎么做网站seo方案模板
  • wordpress缩略图插件网络推广seo
  • 手工网站大全做椅子套在线服务器网站
  • 南京协会网站建设搜索引擎优化教程
  • 免费建设网站c3sales衡水seo培训
  • 券妈妈网站是如何做的老域名购买
  • 印度电商平台网站建设策划中国500强最新排名
  • 别人建的网站怎么修改代码做网站用哪个软件
  • 网站开发demo是什么站长工具名称查网站
  • 金华专业做网站线上电商怎么做