代码之家  ›  专栏  ›  技术社区  ›  Djura Marinkov

Scala中的非工作Spark示例,LogisticRetressionTrainingSummary

  •  1
  • Djura Marinkov  · 技术社区  · 7 年前

    我试图实施 this example 对于多项式逻辑回归,但它不识别正在使用的特征。可能是版本不匹配。本部分代码:

    trainingSummary.falsePositiveRateByLabel.zipWithIndex.foreach { case (rate, label) =>
      println(s"label $label: $rate")
    }
    

    的任何成员 LogisticRegressionTrainingSummary 正在被识别, falsePositiveRateByLabel 特别是在给定的示例中。以及代码后面的其他成员: truePositiveRateByLabel , precisionByLabel ,...

    当我转到实现时,我找不到任何可以使用的类似成员,而是使用mllib 2.11。我错过了什么?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Shaido MadHadders    7 年前

    您是对的,这是一个版本控制问题。这个 github code example 您给出的是Spark当前的主分支,其中API的这一部分有一些重大更改。

    您一直在关注Spark 2.3中的代码。然而,目前这个版本还不稳定,无法下载。这就是 version 2.2 branch 相同代码的示例如下所示:

    val training = spark
      .read
      .format("libsvm")
      .load("data/mllib/sample_multiclass_classification_data.txt")
    
    val lr = new LogisticRegression()
      .setMaxIter(10)
      .setRegParam(0.3)
      .setElasticNetParam(0.8)
    
    // Fit the model
    val lrModel = lr.fit(training)
    
    // Print the coefficients and intercept for multinomial logistic regression
    println(s"Coefficients: \n${lrModel.coefficientMatrix}")
    println(s"Intercepts: ${lrModel.interceptVector}")
    // $example off$
    
    spark.stop()
    

    换句话说,您尝试使用的方法尚未在Spark版本中实现。