Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to support Vector Machine in spark mllib Classification

Shulou Source: shulou.com Published: 2022-05-31 19:07:50 10月04日 Update

Editor to share with you how to support vector machines in spark mllib classification. I hope you will get something after reading this article. Let's discuss it together.

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. {SVMWithSGD} import 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 a classification Not regression * support vector machine analysis of gastric cancer metastasis * Created by eric on 16-7-17. * / object SVMTest {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") / / when reading data files, be sure to pay attention to the text format val splits = data.randomSplit (Array (0.7,0.3)) Seed = 11L) / / A pair of data sets are split val parsedData = splits (0) / / split training data val parseTtest = splits (1) / / split test data val model = SVMWithSGD.train (parsedData 50) / / training model val predictionAndLabels = parseTtest.map {/ / calculate the test value case LabeledPoint (label Features) = > / / calculate test value val prediction = model.predict (features) / / calculate test value (prediction Label) / / Storage Test and Forecast} val metrics = new MulticlassMetrics (predictionAndLabels) / / create a validation class val precision = metrics.precision / / Compute Verification Value println ("Precision =" + precision) / / print verification value val patient = Vectors.dense (Array Calculate patient probability if (patient = = 1) println ("the patient's stomach cancer is likely to metastasize.") / / make a judgment of else println ("the patient's gastric cancer has no chance of metastasis.") / / make a judgment / / Precision = 0.55555555555556 / / 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

After reading this article, I believe you have a certain understanding of "how to support vector machines in spark mllib classification". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Patient data cell gastric cancer test classification vector support probability validation article training code endothelium staging variable possibility name factor done Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Docker MySQL Huawei vpn