In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the example analysis of LinearRegression predicted by spark mllib, which is very detailed and has certain reference value. Friends who are interested must finish it!
The relationship between Commodity Price and Consumer input
Commodity demand (y, ton), price (x1, yuan), consumer income (x2, yuan)
Yx1x251181272113231834
Set up the demand function: y = ax1+bx2
Run the following package spark.regressionAnalysis/** * linear regression code to establish the relationship between commodity prices and consumer input. * Forecast prices * / import org.apache.log4j. {Level, Logger} import org.apache.spark.mllib.linalg.Vectorsimport org.apache.spark.mllib.regression. {LabeledPoint, LinearRegressionWithSGD} import org.apache.spark. {SparkConf SparkContext} object LinearRegression {val conf = new SparkConf () / / create environment variable .setMaster ("local") / / set localization handler .setAppName ("LinearRegression") / / set name val sc = new SparkContext (conf) / / create environment variable instance def main (args: Array [String]) {val data = sc.textFile (". / src/main/spark/regressionAnalysis/lr.txt") / / get the dataset path val parsedData = data.map {line = > / / start processing the dataset val parts = line.split ('|') / / partition LabeledPoint according to the comma (parts (0) .dataset Vectors.dense (parts (1). Split (','). Map (_ .toDouble))}. Cache () / / transform data format / / LabeledPoint, numIterations, stepSizeval model = LinearRegressionWithSGD.train (parsedData, 2,0.1) / / build the model val result = model.predict (Vectors.dense (1) 3)) / / through the model prediction model println (model.weights) println (model.weights.size) println (result) / / print the prediction results}}
Lr.txt
| 5 | 1Jing 18 | 1JI 27 | 2113 | 2318 | 3P4 results are shown in the figure.
The above is all the contents of the article "sample Analysis of LinearRegression for spark mllib Forecast". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.