当前位置:网站首页>【机器学习】向量化计算 -- 机器学习路上必经路
【机器学习】向量化计算 -- 机器学习路上必经路
2022-07-01 02:45:00 【计算机魔术师】
欢迎来到
魔术之家!!该文章收录专栏
— 机器学习 —专栏内容
— 【机器学习】浅谈正规方程法&梯度下降 —
— 【机器学习】梯度下降之数据标准化 —
— 【机器学习】logistic分类回归算法—
— 第十届“泰迪杯“感谢学习总结—
一、求解矩阵
在求解矩阵中,往往有很多很好的,经过高度优化的线性代数库,如octave,matlib,python numpy, c++,java.
我们使用这些线性代数库,可以短短几行实现 所要的效果。
阅读本文内容(需要一点点线性代数的知识)
二、例一
例如 求公式:
h ( x ) = ∑ i = 1 n θ i ∗ x i h(x) = \sum_{i=1}^n\theta_i*x_i h(x)=∑i=1nθi∗xi
我们可以通过循环每一个值来求 每一个 i i i所对应的结果,但此时循环的时间复杂度为 O ( n ) O(n) O(n) , 我们可以把 θ i ( i = 1 , 2 , 3... n ) \theta_i(i=1,2,3...n) θi(i=1,2,3...n) 看为 n n n维的列向量, x i x_i xi作为 n n n维的列向量,则原公式即为求两个向量的内积 θ T ∗ x i \theta^T*x_i θT∗xi 来求得方程,这样在numpy中仅仅需要一行代码。如下图(演示代码为octave(matlib开源版))
c++实现
三、例二
- 再看一个复杂一点的例子:
(对梯度下降还不了解建议先食用文章:机器学习】浅谈正规方程法&梯度下降)
在梯度下降(Gradient descent)同步更新参数 θ i ( i = 1 , 2 , 3... m ) 中 \theta_i(i=1,2,3...m)中 θi(i=1,2,3...m)中

我们可以通过循环 i i i得到每个参数更新,但我们是否能用例子一的方法 简化呢,
如图:
我们将所求式子变为 向量之间的运行,
θ = θ − α ∗ δ \theta = \theta - \alpha * δ θ=θ−α∗δ
(其中: δ δ δ = ∑ x = 1 n ( h θ ( x ) − y i ) 2 n ∗ x i \sum_{x=1}^n \frac{(h_\theta(x) - y_i)^2}{ n }*x_i ∑x=1nn(hθ(x)−yi)2∗xi, h θ ( x ) − y i h_\theta(x) - y_i hθ(x)−yi 是一个实数, x i x_i xi是特征维度的列向量)
此时参数 θ i \theta_i θi也能同步更新,符合要求
四、写在最后
在面对,数据为百万级别,千万级别,或者特征为百万级别,特征级别,向量化计算对提高运算效率非常高效,比
for循环要好用得多,这在机器学习中是非常常见的,一定要掌握
边栏推荐
- Evaluation of the entry-level models of 5 mainstream smart speakers: apple, Xiaomi, Huawei, tmall, Xiaodu, who is better?
- 鼠标悬停效果一
- Sampling Area Lights
- If I am in Beijing, where is a better place to open an account? In addition, is it safe to open a mobile account?
- 集群方法同步执行框架 Suona
- ipmitool下载地址和编译安装时可能出现的问题
- Borrowing constructor inheritance and composite inheritance
- Mouse over effect VI
- 基于OPENCV和图像减法的PCB缺陷检测
- The mobile edge browser cannot open the third-party application
猜你喜欢

Restcloud ETL实践之数据行列转换

如何在智汀中實現智能鎖與燈、智能窗簾電機場景聯動?

Find the length of the common part of two line segments

Sampling Area Lights

Image preloading in JS

Xception learning notes
![[JS] [Nuggets] get people who are not followers](/img/cc/bc897cf3dc1dc57227dbcd8983cd06.png)
[JS] [Nuggets] get people who are not followers

Zero foundation self-study SQL course | window function

详解数据治理知识体系

RestCloud ETL WebService数据同步到本地
随机推荐
VirtualBox installation enhancements
SAP ALV summary is inconsistent with exported excel summary data
ssh配置免密登录时报错:/usr/bin/ssh-copy-id: ERROR: No identities found 解决方法
旷世轻量化网络ShuffulNetV2学习笔记
园区运营效率提升,小程序容器技术加速应用平台化管理
联想X86服务器重启管理控制器(XClarity Controller)或TSM的方法
Use ipmitool to configure BMC network and user information of X86 server
Gartner research: in China, the adoption of hybrid cloud has become the mainstream trend
Big orange crazy blog move notice
Record a service deployment failure troubleshooting
MCU firmware packaging Script Software
servlet【初识】
Comment réaliser la liaison entre la serrure intelligente et la lampe, la scène du moteur de rideau intelligent dans le timing intelligent?
鼠标悬停效果一
Voici le programme de formation des talents de SHARE Creators!
PTA 1017
C # generates PPK files in putty format (supports passphrase)
Cluster method synchronous execution framework suona
pycharm 软件deployment 灰色 无法点
Mouse over effect 9
