胃癌转移数据说明
肾细胞癌转移情况(有转移 y=1,无转移 y=2)x1:确诊时患者年龄(岁)x2:肾细胞癌血管内皮生长因子(VEGF),其阳性表述由低到高共3个等级x3:肾细胞癌组织内微血管数(MVC)x4:肾癌细胞核组织学分级,由低到高共4级x5:肾细胞癌分期,由低到高共4级y x1 x2 x3 x4 x50 59 2 43.4 2 1
运行代码如下
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分类,逻辑回归,是分类,不是回归 * 胃癌转移判断 * Created by eric on 16-7-17. */object LogisticRegression4 { val conf = new SparkConf() //创建环境变量 .setMaster("local") //设置本地化处理 .setAppName("LogisticRegression4")//设定名称 val sc = new SparkContext(conf) def main(args: Array[String]) { val data = MLUtils.loadLibSVMFile(sc, "./src/main/spark/logisticRegression/wa.txt") //读取数据文件,一定注意文本格式 val splits = data.randomSplit(Array(0.7, 0.3), seed = 11L) //对数据集切分 val parsedData = splits(0) //分割训练数据 val parseTtest = splits(1) //分割测试数据 val model = LogisticRegressionWithSGD.train(parsedData,50) //训练模型 val predictionAndLabels = parseTtest.map {//计算测试值 case LabeledPoint(label, features) => //计算测试值 val prediction = model.predict(features)//计算测试值 (prediction, label) //存储测试和预测值 } val metrics = new MulticlassMetrics(predictionAndLabels)//创建验证类 val precision = metrics.precision //计算验证值 println("Precision = " + precision) //打印验证值 val patient = Vectors.dense(Array(70,3,180.0,4,3)) //计算患者可能性 if(patient == 1) println("患者的胃癌有几率转移。")//做出判断 else println("患者的胃癌没有几率转移。") //做出判断 //Precision = 0.3333333333333333 //患者的胃癌没有几率转移。 }}
wa.txt
0 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:3 5: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 3:127.2 4:3 5:30 1:31 2:2 3:124.8 4:2 5:3
结果如图