spark.mllib源代码阅读-优化算法1-Gradient
Spark中定义的损失函数及梯度,在看源代码之前,先回想一下机器学习中定义了哪些损失函数,毕竟梯度求解是为优化求解损失函数服务的。
监督学习问题是在如果空间F中选取模型f作为决策函数。对于给定的输入X,由f(X)给出对应的输出Y,这个输出的预測值f(X)与真实值Y可能一致也可能不一致,用一个损失函数(lossfunction)或代价函数(cost function)来度量预測错误的程度。损失函数是f(X)和Y的非负实值函数,记作L(Y, f(X)).
统计学习中经常使用的损失函数有下面几种:
(1) 0-1损失函数(0-1 loss function):
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASoAAABACAYAAACtIjqnAAAV2ElEQVR4Ae2dedRN1RvHtyFT5plIKEVUxoxZlAwVKhkyJauICqFVhlWtpIQkCiVi9YcpZJYxCcmsECXLnFnm8fzW51k993dd9973vdN5r/vuvda955w9PPt5nn32c/be5/nuk8ZxHMfYYDVgNWA1EMcaSBvHvFnWrAasBqwGRAPWUNkbwWrAaiDuNWANVdw3kWXQasBqwBoqew9ETQPXr18XWv/8849p1KiRKVmyZNRoW0KpWwPWUKXu9o+a9BiptGnTml9++cVUqFDBHDp0yMyePTtq9C2h1K2BNPatX+q+AaIhPS+O06RJY7Zv326qVKliChUqZDZt2mSyZMkSDfKWhtWAsSMqexNERQNXrlwxbdu2NWfPnjWTJk0SI3X16tWo0LZErAasobL3QEQauHbtmoym5s+fb9avXy9rU0z9mAqmT58+ItqJVFjX7yZMmGCmTZsWVdGU9syZM03Xrl2jQpt2ff75580333wj9LSOqBAPg4g1VGEozRa5WQN0EtaonnrqKUm8FfyI586da+68806TI0cOkzt3bpM3b17zxBNPCP90VMLEiRNN4cKFTaZMmUy2bNlMx44dJT7UP6bGly5dMhiqBx54IKTiqsuff/5ZptZlypQxvXr1EhqkofedO3eawYMHmz59+nhoq3H58ccfTfHixUXG7Nmzm3z58pnHHnvMXL582Zw+fdqUK1fOZMyYUR44+fPnN507dzbp0qUzH3/8sXnvvffM8uXLpQ7lw1OBmy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w+bWrVqmR07drjIha0qkTVgR1SJ3Louy6Zvn/C7adu2rfjf7Nu3z2UubHWJqAFrqBKxVa1MVgMJpgE79UuwBrXiWA0kogasoUrEVrUyWQ0kmAasoUqwBrXiWA0kogasoUrEVrUyWQ0kmAb+Byny0UmOYVQJAAAAAElFTkSuQmCC" alt="" />
(2) 平方损失函数(quadraticloss function)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQIAAAApCAYAAADeUycRAAAMFklEQVR4Ae1beWxNzxef1toqUbsivkWstZSgLbEL9Ye1aWwR0UglmtJYIkWQSIPYlwQhVERqXxtbVYnE3iLWCpGqlFKtrZZifvmcfM9z+373Xe3tm3q+nUnem7kzZ86czzlnzl1mxktKKYVOWgNaAxVaA94VGr0GrzWgNUAa0IFAO4LWgNaA0IFAO4HWgNaADgTaB7QGtAaEDgTaCbQGtAZ0INA+oDWgNSB0INBOoDXgcRrYvHmzGDdunAgKChKRkZHi06dPymWsrHwEPYDWgNZAiTVw+vRpkZSUJFJSUkR+fr5o3bq1iI2NFdu3by8xDzuEetXAjtZ0H60BRRp49eqVuHDhgrh7966oX7++GDFihNizZ4+i0X6x1U8Ev3ShS1oDf1wDY8aMEa1atRLt27cnWV68eCFatGihXC79RKBcxXoArYFfGvjx44cYP3682LlzJ1X+/PnzV6MQokaNGiIsLExUrVpV3LlzR1y8eFFs2rSpGI2KC48KBKyUI0eOiOnTp6vAWyaeKuSzcgyrtjIBsdFZBXYbYri1iwpMv7NZpUqVxIoVK8SSJUtEWlqa8Pb2FsbjPiiDR15enpg8ebLYvXu36Nevn1txmzLDoSMV6cePH8R206ZNMiAgQPr5+eFwk6xXr55s0qSJnDt3LrUz3c+fP+n60aNHMiwsTGZnZ9P1iRMnZLNmzWStWrWkv7+/rFu3rhw2bBi1ff/+nfLExETZuHFjWa1aNRpnypQpVF/aP5bh0qVLsnv37rJdu3Zy1qxZxIbbnOVDI2NIS0uT//zzD8lZs2ZNwjpw4ED59etXWVBQIIOCgmTVq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CqwBHQgqsPE1dK0B1oAOBKwJnWsNVGAN/A/mH+C3cwZxagAAAABJRU5ErkJggg==" alt="" />
(3) 绝对损失函数(absolute lossfunction)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAP4AAAAmCAYAAADk+yYTAAALVklEQVR4Ae1caWxNTxSfFlVStZaqNrQEDQ0lKBqNIsQHtZSINmKJVELQUBElfBARQa2JCqHig1prC6XWSFq1S2hpiFhip5baWuaf34lz/7e37/Utffe917yZ5PXOzDlz1jmz3JlbPymlFCopCygL+JQF/H1KW6WssoCyAFlABb7qCMoCPmgBFfg+6HSlsrKACnzVB5QFfNACKvB90OlKZWUBFfiqDygL+KAFVOD7oNOVysoCKvBVH1AW8EELqMD3QacrlZUFVOCrPqAs4IMWUIHvg05XKisLeHXg//37lzyUl5cn5syZ41XeMkO2P3/+iClTpog9e/aQrsyDFbcFZzwzn79//xYTJ040k4XbabOdXdnP7PGVR22Jj3TMTn/+/CEW27Ztk2FhYTIoKAgfBsk2bdrIDh06yMWLFxOc8VD4+/cv1T18+FAOGjRIvnjxgsonT56UERERMjg4WLZs2VK2bt1ajh49mmBVVVX0zMnJke3bt5eNGzcmXjNmzKB6R/4w/6tXr8p+/frJ6OhouXDhQiLBMKNsALIOly5dkp06dSIZmzVrRroOGzZM/vr1S5aXl8uePXvKgIAAskNISIhMS0sj2s+fP6d2Fy9erMaLClJKW3DGM+v548cP2bdvX428u/yhMXQiw/7yNl8abemEak43EU63dKIhOv2HDx9kly5dZGBgoCwrK6MgQL0xsbMSExMlApnT9+/f5evXr+XYsWMpaObMmSMrKiokBz2eaNu/f385YcIEWVxcLD9//szNHXpCLsiampoqQ0NDZdu2bam9Ndn0xOHUT58+ya1bt5KcCQkJ8ufPn7KyspLQoFOTJk3kzp075dOnT+W3b9+0QePQoUM0oEFu5oVGPKhYg+v5m5WHDgMHDtTIu9MfGlMnMt7mS6hgtKUTajndxG2Bzx341atX0t/fX8bHx1sVmjs4z5oczGjAdE6dOkUB1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SooHjpfnz50tcQcbR3ogRI+TIkSPlgQMHCM5HmXwMhbsDWNycPXuW4PzHFpzxzHpaOnt21h9myQi69cGXlmxppk30tDH7eF3iIEDg4C4+kjH4nBEaA0Nubm6Nm2dGWvn5+RR0t2/fJhAHGwpmycYysJ74oKlVq1Y0yDAMT1twPa4ZeU92Vmf08WZfetKWpi/17Vp2GJCwdESaPXu2WLhwIS2Neb9mQLW7CJo4+8Y+mz97NTbGqQJS8+bNaduBbQkSloyczJCNaet57dy5U0yfPl3gSE+fWBZrcD2uL+frgy896h9nRlF3tMEsix9u42G7UNfEMzU+f920aVMNcrj5h6U1vurDZ6erVq0iHG6nb+Bq2Zg28zp37hzd2sPtRkurDWtwpmPm05O3zezVqz74Erp40pZeudSHUbjDFxUVybi4OKc/rdV3llu3btG7AHwYY0y4Qjt16lSJ9w7Tpk2jj2NYBiMu17tSNuaBj3i6du0qT5w4QVU8GNgLZzyznlie6r+INItPXejWF1960pZeG/hwPHd6fNTCe/26dAhXtjVDNuzf8V1AVlYWico8WG5bcMYz84n3JLV9Um0mb7Nos51d2c/s8ZUnbekHY3p0r6GYKwsoC7jdAv9/FeN21oqhsoCygKcsoALfU5ZXfJUFPGgBFfgeNL5irSzgKQuowPeU5RVfZQEPWkAFvgeNr1grC3jKAirwPWV5xVdZwIMW+A9O7UCn6JFuHQAAAABJRU5ErkJggg==" alt="" />
(4) 对数损失函数(logarithmicloss function) 或对数似然损失函数(log-likelihood loss function)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASYAAAAmCAYAAABpszZuAAANQ0lEQVR4Ae1ceWxNzxefVltUSWurUmqLfS8tVVpKrLEEsSZiiZJKaCgpFSQi0YhdYg0tf9i1qH1fa18SFCH2rYqi1Dq/fE6+5+b2ee3zVvfnzSSv996ZMzOf+cyZc88stx5SSilUUAwoBhQDBmLA00BYFBTFgGJAMUAMKMOkFEExoBgwHAPKMBmuSxQgxYBiQBkmpQOKAcWA4RhQhslwXaIAKQYUA8owKR1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g==" alt="" />
在不考虑过拟合的情况下。损失函数越小,模型就越好。
Spark中定义梯度和损失函数求解的类包含一个Gradient基类及其三个实现类:
Gradient
梯度计算的抽象类,定义了计算梯度值和损失函数值的compute函数:
def compute(data: Vector, label: Double, weights: Vector): (Vector, Double) = {
val gradient = Vectors.zeros(weights.size)
val loss = compute(data, label, weights, gradient)
(gradient, loss)
}
后面的梯度计算类都继承子Gradient类并实现compute函数。
LeastSquaresGradient
实现了最小二乘法进行线性回归的梯度计算方法。
其对compute函数进行的覆写
override def compute(data: Vector, label: Double, weights: Vector): (Vector, Double) = {
val diff = dot(data, weights) - label
val loss = diff * diff / 2.0
val gradient = data.copy
scal(diff, gradient)//常数乘以向量 更新后的gradient即为梯度 gradient=(y - lable)* x
(gradient, loss)
}
使用场景:
1、 參数预计的方法是最小化误差的平方和,其他预计方法不适合用此梯度算子。
2、 Spark实现的是线性回归的梯度计算。非线性回归的梯度计算不适合使用此算子。
HingeGradient
实现了最大化分类间距的hinge loss进行參数预计的梯度下降方法,对compute函数进行的覆写:
class HingeGradient extends Gradient {
override def compute(data: Vector, label: Double, weights: Vector): (Vector, Double) = {
val dotProduct = dot(data, weights)
// Our loss function with {0, 1} labels is max(0, 1 - (2y - 1) (f_w(x)))
// Therefore the gradient is -(2y - 1)*x
val labelScaled = 2 * label - 1.0
if (1.0 > labelScaled * dotProduct) {
val gradient = data.copy
scal(-labelScaled, gradient)
(gradient, 1.0 - labelScaled * dotProduct)
} else {
(Vectors.sparse(weights.size, Array.empty, Array.empty), 0.0)
}
}
使用场景:
适用于利用最大化分类间隔思想来构建分类器,典型的使用如SVM。
LogisticGradient
使用对数似然损失函数对Logistic分类/回归进行參数预计的梯度下降方法。实现的代码比較长,在此就不贴了,在内部分了2分类和多分类两种情况进行计算。
spark.mllib源代码阅读-优化算法1-Gradient的更多相关文章
- Spark MLlib中KMeans聚类算法的解析和应用
聚类算法是机器学习中的一种无监督学习算法,它在数据科学领域应用场景很广泛,比如基于用户购买行为.兴趣等来构建推荐系统. 核心思想可以理解为,在给定的数据集中(数据集中的每个元素有可被观察的n个属性), ...
- Spark MLlib之水塘抽样算法(Reservoir Sampling)
1.理解 问题定义可以简化如下:在不知道文件总行数的情况下,如何从文件中随机的抽取一行? 首先想到的是我们做过类似的题目吗?当然,在知道文件行数的情况下,我们可以很容易的用C运行库的rand函数随机的 ...
- 用Spark学习矩阵分解推荐算法
在矩阵分解在协同过滤推荐算法中的应用中,我们对矩阵分解在推荐算法中的应用原理做了总结,这里我们就从实践的角度来用Spark学习矩阵分解推荐算法. 1. Spark推荐算法概述 在Spark MLlib ...
- Spark 实践——基于 Spark MLlib 和 YFCC 100M 数据集的景点推荐系统
1.前言 上接 YFCC 100M数据集分析笔记 和 使用百度地图api可视化聚类结果, 在对 YFCC 100M 聚类出的景点信息的基础上,使用 Spark MLlib 提供的 ALS 算法构建推荐 ...
- Spark MLlib之线性回归源代码分析
1.理论基础 线性回归(Linear Regression)问题属于监督学习(Supervised Learning)范畴,又称分类(Classification)或归纳学习(Inductive Le ...
- Spark MLlib LDA 基于GraphX实现原理及源代码分析
LDA背景 LDA(隐含狄利克雷分布)是一个主题聚类模型,是当前主题聚类领域最火.最有力的模型之中的一个,它能通过多轮迭代把特征向量集合按主题分类.眼下,广泛运用在文本主题聚类中. LDA的开源实现有 ...
- Spark MLlib 示例代码阅读
阅读前提:有一定的机器学习基础, 本文重点面向的是应用,至于机器学习的相关复杂理论和优化理论,还是多多看论文,初学者推荐Ng的公开课 /* * Licensed to the Apache Softw ...
- Apache Spark源码走读之22 -- 浅谈mllib中线性回归的算法实现
欢迎转载,转载请注明出处,徽沪一郎. 概要 本文简要描述线性回归算法在Spark MLLib中的具体实现,涉及线性回归算法本身及线性回归并行处理的理论基础,然后对代码实现部分进行走读. 线性回归模型 ...
- Spark MLBase分布式机器学习系统入门:以MLlib实现Kmeans聚类算法
1.什么是MLBaseMLBase是Spark生态圈的一部分,专注于机器学习,包含三个组件:MLlib.MLI.ML Optimizer. ML Optimizer: This layer aims ...
随机推荐
- 【Linux】Ubuntu配置服务自启动 sysv-rc-conf
在Ubuntu下,配置服务系统开机自启动,使用的不是chkconfig,而是sysv-rc-conf. 且看如下: 安装: sudo apt-get install sysv-rc-conf 帮助信息 ...
- centos下安装配置mongodb
1:安装mkdir -p /app/mongodb tar zxvf mongodb-linux-x86_64-rhel62-3.4.6.tgz vi .bash_profile PATH=$PATH ...
- editcap的使用
editcap.exe -h Editcap (Wireshark) (v2.-gf42a0d2b6c) Edit and/or translate the format of capture fil ...
- Run Test Case on Spark
今天有哥们问到怎样对Spark进行单元測试.如今将Sbt的測试方法写出来,例如以下: 对Spark的test case进行測试的时候能够用sbt的test命令: 一.測试所有t ...
- js自动补全空白列(即缺少td的列)
//自动补全空白列 var rows = document.getElementById("gridTable").rows; //行对象 var allcells = rows[ ...
- cocos2d-js 各浏览器上的表现
其实这里只简单对比3个浏览器,估计也足够代表性了. 结论是: 1.有webgl支持的时候,就可以尽情的耍吧: 2.没有webgl,能native就native.如果不行,就只能在canvas上做小块的 ...
- Java AtomicBoolean (Java代码实战-008)
值得一提的是,Java的AtomXXX类并不是使用了锁的方式进行同步,而是采用了一种新的理念,叫做CAS(Compare And Swap)CAS是一组CPU原语指令,用来实现多线程下的变量同步(原子 ...
- Axure 万年历(日期选择下拉文本框)
百度网盘:http://pan.baidu.com/s/1c1ZjUPq 点击“图1”可呈现出“图2”的效果.(已实现模板化功能,不用去研究去为什么,直接使用即可)
- Javascript调试利器console的使用
一.Console API Console.assert() 判断第一个参数是否为真,false的话抛出异常并且在console输出相应信息. Console.count() 以参数为标识记录调用的次 ...
- jQuery对象复制
// 浅层复制(只复制顶层的非 object 元素) var newObject = jQuery.extend({}, oldObject); // 深层复制(一层一层往下复制直到最底层) var ...