当前位置:网站首页>机器学习之线性回归详解
机器学习之线性回归详解
2022-07-01 10:07:00 【HUIM_Wang】
机器学习之线性回归详解
线性回归的算法:
重点介绍梯度下降算法。
评估模型好坏的方法:损失函数(lost function)
最简单常见的损失函数:最小均方差(mse)
公式如下:
预测房价数据,假如模型y=1,最终的值60132无实际意义,但是在对比之下,值越小越好。最好的最小均方差是尽量接近0的,但是根据数据样本不同,不可能等于0
假如预测房价,特征值是面积,目标值是房价,需要拟合出一条线,计算出权重m和b
步骤一:假设m=0,即y=b,则b为唯一的可调参数,利用最小均方差公式,计算出最小的最小均方差,在此过程中拟合出一个最优的参数b

从上得知,“最优”的b值应该是mse=612对应的241附近,这样的话较为符合房价的价格。(这个过程需要一个一个地找最小mse对应的b,比较麻烦,并且图中给的b是从1开始找的,因为不确定b的值,一旦b的值为负值就麻烦了)
为了能尽快并且准确地找到最合适的b,需要引入一个新概念:学习速率(learning rate)
先看一组图:
需要找到最小的mse对应的b点



不管b从何值开始取,都需要让计算机根据线的趋势动态地找到最小mse值,即求导数,

根据上图,求出的导最小值是-8,对应着最小均方差,此时b=241
尽管如此,此时的b仍是我们用肉眼观察到的最小值,并且b的变化和取值是我们人工加上去的f,计算机可理解不了,我们需要根据一些信号量来调整b的变化。
假如曲线很陡峭的话,例如图b,斜率的值会负的很离谱,那接下来的预测点就是在曲线的右边而不是左边;如果是图a情况,斜率会很大,应该让b往左边偏移 ,也就是说如果斜率为负值,那么接下来的猜测点应该往右移,如果为正值,应该往左移,直到曲线趋于平缓,导数接近于0.
上面我们提到了学习速率(learning rate),它可以根据mse对b的导数,最快地找到最合适的b,如果导数负的越大,那么它就应该变化的越多,如果导数越小,越接近于0,那么它应该变化的越小。
学习速率是一个值,例如0.0001,学习速率是这样用的:本次的b=上一个b - 上一个导数 * 学习速率,如此循环迭代下去,可以很快的找到最接近0的导数对应的b 。
如果学习速率越小的话,例如0.000001,那么b的值变化的越慢,如果学习速率越大的话,例如0.1、0.8,b值变化的越快。变化的越慢就代表要进行大量的迭代,计算量大,不过最终求出的b值会越精确;变化的越快计算量也相应少了很多,但是b值可能不是最好的那个。
如下图:当学习速率为0.00001、0.001,0.01、0.1时:




当learning rate 为0.2时,b慢慢的趋近于245,导数慢慢的趋近于0
learning rate的值不能太大,否则b只会离正确的点越来越远
为了简化模型,以上便是y=mx+b,(m=0)情况下,求可调参数也就是权重b的值。(这是一种极端情况,正常情况下m≠0)
所以一般情况下我们要对m和b分别求导:
同理,得出:
边栏推荐
- JD and Tencent renewed the three-year strategic cooperation agreement; The starting salary rose to 260000 yuan! Samsung sk of South Korea competes for salary increase to retain semiconductor talents;
- Prefabricated dishes usher in the "golden age", who can lead the next trillion market
- Apple amplification! It's done so well
- [fxcg] large scale job hopping may be one of the driving forces behind the soaring inflation in the United States
- Centos 配置discuz 提示请检查 mysql 模块是否正确加载
- 苹果放大招!这件事干的太漂亮了……
- STM32逆变器电源设计方案,基于STM32F103控制器[通俗易懂]
- Introduction to expressions and operators in C language
- 客户端如何请求数据库?
- In terms of use
猜你喜欢

电脑USB、HDMI、DP各种接口及速度

直播管理项目

This is the best flash popular science article I have ever seen!

What if the win11 account is locked and unable to log in? Win11 account is locked and unable to log in

Japanese professor sues Intel FPGA and SOC products for infringing a design patent

持续进阶,软通动力稳步推动云智能战略

Programmers want to go to state-owned enterprises? The technology is backward and the salary is low. I can't find a job after lying flat for several years

那个程序员,被打了。

uniapp微信小程序组件按需引入

Hardware midrange project
随机推荐
Is it safe to do fund fixed investment on CICC securities?
Win11账号被锁定无法登录怎么办?Win11账号被锁定无法登录
TC8:UDP_ USER_ INTERFACE_ 01-08
4hutool实战:DateUtil-格式化时间[通俗易懂]
Japanese professor sues Intel FPGA and SOC products for infringing a design patent
Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
谁还在买“三只松鼠”们
Module 9: design e-commerce seckill system
Some tools used in embedded development
一个悄然崛起的国产软件,低调又强大!
哪个券商公司炒股开户佣金低又安全又可靠
PO模式深入封装
Does anyone know the logic of limit statement execution in Clickhouse? In the picture, the SQL above can be executed successfully
High precision factorial
Continue to advance, and softcom power steadily promotes cloud intelligence strategy
CSDN's one-stop cloud service is open for internal testing, and new and old users are sincerely invited to grab the fresh
A quietly rising domestic software, low-key and powerful!
Kotlin 协程调度切换线程是时候解开真相了
Zero foundation software testing must see, 10 years of testing old bird's conscience suggestions (a total of 15)
Flinkv1.13 implementation of financial anti fraud cases