zoukankan      html  css  js  c++  java
  • 成功秀了一波scala spark ML逻辑斯蒂回归

    1、直接上官方代码,调整过的,方可使用

    package com.test
    import org.apache.spark.{SparkConf, SparkContext}
    import org.apache.spark.mllib.classification.{LogisticRegressionModel, LogisticRegressionWithLBFGS}
    import org.apache.spark.mllib.evaluation.MulticlassMetrics
    import org.apache.spark.mllib.regression.LabeledPoint
    import org.apache.spark.mllib.util.MLUtils
    
    object logsitiRcongin {
    
      def main(args: Array[String]): Unit = {
        val conf = new SparkConf().setMaster("local").setAppName("df")
        val sc = new SparkContext(conf)
    
        // Load training data in LIBSVM format.
        val data = MLUtils.loadLibSVMFile(sc, "E:\spackLearn\spark-2.3.3-bin-hadoop2.7\data\mllib\sample_libsvm_data.txt")
    
        // Split data into training (60%) and test (40%).
        val splits = data.randomSplit(Array(0.6, 0.4), seed = 11L)
        val training = splits(0).cache()
        val test = splits(1)
    
        // Run training algorithm to build the model
        val model = new LogisticRegressionWithLBFGS()
          .setNumClasses(10)
          .run(training)
    
        // Compute raw scores on the test set.
        val predictionAndLabels = test.map { case LabeledPoint(label, features) =>
          val prediction = model.predict(features)
          (prediction, label)
        }
    
        // Get evaluation metrics.
        val metrics = new MulticlassMetrics(predictionAndLabels)
        val accuracy = metrics.accuracy
        println(s"最后的得分:Accuracy = $accuracy")
    
        // Save and load model
        model.save(sc, "data/model/scalaLogisticRegressionWithLBFGSModel")
        val sameModel = LogisticRegressionModel.load(sc, "data/model/scalaLogisticRegressionWithLBFGSModel")
    
        while (true){
        }
    
      }
    }
    

      

    最后查看任务调度

     

  • 相关阅读:
    HDU1712:ACboy needs your help(分组背包模板)
    HDU1203:I NEED A OFFER!(01背包)
    HDU1171:Big Event in HDU
    POJ1014:Dividing(多重背包)
    HDU2191-悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包入门)
    hdu2159FATE(二维背包)
    POJ1201 Intervals
    C++之运算符重载
    C++之强制类型转换
    MFC WinInetHttp抓取网页代码内容
  • 原文地址:https://www.cnblogs.com/wuzaipei/p/10974978.html
Copyright © 2011-2022 走看看