How to realize the Random gradient Descent method in spark mllib
Editor to share with you how to achieve spark mllib random gradient descent method, I hope you will learn something after reading this article, let's discuss it together!
The running code is as follows: package spark.regressionAnalysis/** * random gradient descent (stochastic gradient descent,SGD) * SGD is a variation of the steepest gradient descent method. * using the steepest gradient descent method, N iterations will be carried out until the objective function converges or reaches a certain convergence limit. * m samples will be calculated in each iteration, resulting in a large amount of calculation. * to simplify the calculation, SGD calculates the gradient for only one sample per iteration until it converges. * Random gradient descent, i.e. (the fastest way down from the top of Zijinshan Mountain) * * Created by eric on 16-7-10. * / import scala.collection.mutable.HashMapobject SGD {val data = HashMap [Int,Int] () / create dataset def getData (): HashMap [Int Int] = {/ / generate the content of the dataset for (I (16roomi)) / / write the formula yroom16x} data / / return the dataset} var θ: Double = 0 / / the first step assumes that θ is 0 var α: Double = 0.1 / / set the step coefficient The magnitude of each drop def sgd (XGV double) = {/ / set iterative formula θ = θ-α * ((θ * x)-y) / / iterative formula} def main (args: Array [String]) {val dataSource = getData () / / get the dataset dataSource.foreach (myMap = > {/ / start iterative sgd (myMap._1) MyMap._2) / / input data}) println ("final result θ value" + θ) / / display result}} result as shown in the figure
After reading this article, I believe you have a certain understanding of "how to achieve random gradient descent in spark mllib". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!