当前位置:网站首页>正规方程、、、
正规方程、、、
2022-06-24 09:40:00 【Wanderer001】
目录
一、什么是正规方程
梯度下降法计算参数最优解,过程是对代价函数的每个参数求偏导,通过迭代算法一步步更新,直到收敛到全局最小值,从而得到最优参数。
正规方程是一次性求得最优解。
思想:对于一个简单函数,对参数求导,将其值置为0,就得到参数的值。像下面这样:

现实例子有很多参数,我们要对这些参数都求偏导数,得到各个参数的最优解,也就是全局最优解。但是困难在于,这样做非常浪费时间。
二、正规方程的使用
举例如下:

这里4个样本,以及4个特征变量x1,x2,x3,x4,观测结果是y,在列代价函数的时候,需要加上一个末尾参数x0,如下:

再将特征参数保存在X矩阵中,对观测结果做同样的操作并保存在向量y中,如图:

然后我们通过下面这个公式得出参数θ最优解。
![]()
关于这个式子推到:

对于一个训练样本的所有特征参数可以用x(i)向量来表示(注意x0(i)要加上) ,而设计矩阵就可以表示为X,是所有样本向量的转置,y是观测结果的向量,这样表示之后可以用上面那个公式直接计算Θ的最优解。
三、不可逆情况
注意到正规方程有一个
求逆矩阵的过程,当矩阵不可逆,一般有两种原因:
- 多余特征(线性相关)
- 太多特征(例如:m≤n),解决办法:删除一些特征,或正则化
其实,本质原因还是线性知识:
首先,这是两个必要条件,
根据性质:r(ATA) = r(A),ATA可逆性可转化为A的可逆性。
第一种:实际上是线性相关的列向量,矩阵的秩 < 矩阵的维度,不可逆;
第二种:
- m < n时,也就是维度小于向量个数,在这里也就是样本数小于特征数,线性相关
- m = n时,当|A| = 0时不可逆,|A| != 0时可逆
四、正规方程与梯度下降法的比较
梯度下降法:
缺点:
- 需要选择学习率α
- 需要多次迭代
优点:
- 当特征参数大的时候,梯度下降也能很好工作
正规方程:
缺点:
- 需要计算
,计算量大约是矩阵维度的三次方,复杂度高。 - 特征参数大的时候,计算缓慢
优点:
- 不需要学习率α
- 不需要多次迭代
总结:取决于特征向量的个数,数量小于10000时,选择正规方程;大于10000,考虑梯度下降或其他算法。
边栏推荐
- PHP file lock
- canvas 绘制图片
- Symbol. Iterator iterator
- Baidu AI template for knowledge understanding
- GeoGebra 实例 时钟
- NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!
- 上升的气泡canvas破碎动画js特效
- How to solve multi-channel customer communication problems in independent stations? This cross-border e-commerce plug-in must be known!
- [input method] so far, there are so many Chinese character input methods!
- How to standardize data center infrastructure management process
猜你喜欢

如何规范化数据中心基础设施管理流程

CVPR 2022 oral | NVIDIA proposes an efficient visual transformer network a-vit with adaptive token. The calculation of unimportant tokens can be stopped in advance

canvas掉落的小球重力js特效动画

Indexeddb local storage, homepage optimization

indexedDB本地存储,首页优化

Mise en œuvre du rendu de liste et du rendu conditionnel pour l'apprentissage des applets Wechat.

微信小程序學習之 實現列錶渲染和條件渲染.

机器学习——感知机及K近邻

Wechat applet learning to achieve list rendering and conditional rendering

ByteDance Interviewer: talk about the principle of audio and video synchronization. Can audio and video be absolutely synchronized?
随机推荐
卷妹带你学jdbc---2天冲刺Day1
利用pandas读取SQL Sever数据表
Amendment to VPP implementation policy routing
dedecms模板文件讲解以及首页标签替换
Engine localization adaptation & Reconstruction notes
Programming questions (continuously updated)
canvas管道动画js特效
NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!
Queue queue
如何提高网络基础设施排障效率,告别数据断档?
vim的使用
js单例模式
Internet of things? Come and see Arduino on the cloud
Is there a reliable and low commission futures account opening channel in China? Is it safe to open an account online?
数组无缝滚动demo
Troubleshooting steps for Oracle pool connection request timeout
队列Queue
Detailed explanation of PHP singleton mode
TP5 using post to receive array data times variable type error: solution to array error
El table Click to add row style