In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.