Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize logical regression in spark mllib Classification and Prediction

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "how to achieve logical regression of spark mllib classification prediction". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to realize logical regression of spark mllib classification prediction".

The metastatic data of gastric cancer showed that the metastasis of renal cell carcinoma (with metastasis 1, without metastasis 2) x1: age (age) x2: renal cell carcinoma vascular endothelial growth factor (VEGF), its positive expression from low to high a total of 3 grades x3: renal cell carcinoma tissue microvessel count (MVC) x4: renal cell carcinoma nuclear histological grade, from low to high grade x5: renal cell carcinoma stage. From low to high, four levels of y x 1 x 2 x 3 x 4 x 50 59 2 43.4 21 are run as follows: package spark.logisticRegressionimport org.apache.spark.mllib.classification.LogisticRegressionWithSGDimport org.apache.spark.mllib.evaluation.MulticlassMetricsimport org.apache.spark.mllib.linalg.Vectorsimport org.apache.spark.mllib.regression.LabeledPointimport org.apache.spark.mllib.util.MLUtilsimport org.apache.spark. {SparkConf, SparkContext} / * MLLib classification, logical regression, is classification Not regression * gastric cancer metastasis judgment * Created by eric on 16-7-17. * / object LogisticRegression4 {val conf = new SparkConf () / / create the environment variable .setMaster ("local") / / set the localization handler .setAppName ("LogisticRegression4") / / set the name val sc = new SparkContext (conf) def main (args: Array [String]) {val data = MLUtils.loadLibSVMFile (sc, ". / src/main/spark/logisticRegression/wa.txt") / / read the data file Be sure to pay attention to the text format val splits = data.randomSplit (Array (0.7,0.3), seed = 11L) / / A pair of dataset segmentation val parsedData = splits (0) / / split training data val parseTtest = splits (1) / / split test data val model = LogisticRegressionWithSGD.train (parsedData) 50) / / training model val predictionAndLabels = parseTtest.map {/ / calculate test value case LabeledPoint (label, features) = > / / calculate test value val prediction = model.predict (features) / / calculate test value (prediction Label) / / Storage Test and Forecast values} val metrics = new MulticlassMetrics (predictionAndLabels) / / create validation class val precision = metrics.precision / / calculate verification value println ("Precision =" + precision) / / print verification value val patient = Vectors.dense (Array 3)) / / calculate the patient probability val prediction = model.predict (patient) if (prediction = = 1) println ("the patient's gastric cancer has a chance of metastasis.") / / make a judgment of else println ("the patient's gastric cancer has no chance of metastasis.") / / make a judgment / / Precision = 0.33333333333333 / / the gastric cancer of the patient has no chance of metastasis. }} wa.txt0 1:59 2:2 3:43.4 4:2 5:10 1:36 2:1 3:57.2 4:1 5:10 1:61 2:2 3:190 4:2 5:11 1:58 2:3 3:128 4:4 5:31 1:55 2:3 3:80 4:3 5:40 1:61 2:1 3:94 4:4 5:20 1:38 2:1 3:76 4:1 5:10 1:42 2:1 3:240 4:3 5:20 1:50 2:1 3:74 4:1 5:10 1:58 2:2 3:68.6 4:2 5:20 1:68 2:3 3:132.8 4:4 5:21 1:25 2:2 3:94.6 4:4 5:30 1:52 2:1 3:56 4:1 5:10 1:31 2:1 3:47.8 4:2 5:11 1:36 2:3 3:31.6 4: 35: 10 1:42 2:1 3:66.2 4:2 5:11 1:14 2:3 3:138.6 4:3 5:30 1:32 2:1 3:114 4:2 5:30 1:35 2:1 3:40.2 4:2 5:11 1:70 2:3 3:177.2 4:4 5:31 1:65 2:2 3:51.6 4:4 5:40 1:45 2:2 3:124 4:2 5:41 1 68 2:3 3lav 127.2 4:3 5:30 1:31 2:2 3Rd 124.8 4:2 5:3 the result is shown in the picture

The above is all the content of the article "how to realize logical regression of spark mllib classification prediction". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report