如何从Spark ML Logistic回归模型获取模型摘要?

时间:2018-12-27 15:56:10

标签: apache-spark-ml

我正在跟踪-https://spark.apache.org/docs/2.3.0/ml-classification-regression.html#multinomial-logistic-regression

中的示例

当我尝试获取模型摘要时,我遇到了一个错误。这是我的错误代码-

// START 

import org.apache.spark.ml.classification.LogisticRegression

// Load training data
val training = spark.read.format("libsvm").load("file:///Users/my_username/Desktop/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: \n${lrModel.interceptVector}")

val trainingSummary = lrModel.summary
org.apache.spark.SparkException: No training summary available for this LogisticRegressionModel
  at org.apache.spark.ml.classification.LogisticRegressionModel$$anonfun$summary$1.apply(LogisticRegression.scala:1002)
  at org.apache.spark.ml.classification.LogisticRegressionModel$$anonfun$summary$1.apply(LogisticRegression.scala:1002)
  at scala.Option.getOrElse(Option.scala:121)
  at org.apache.spark.ml.classification.LogisticRegressionModel.summary(LogisticRegression.scala:1001)
  ... 48 elided

我想在此步骤之后从模型中打印指标。

我已经从-https://github.com/apache/spark/blob/master/data/mllib/sample_multiclass_classification_data.txt

获得了数据

1 个答案:

答案 0 :(得分:0)

不好,我使用的是Spark版本2.2.0,文档中说使用的是2.3.0

它适用于2.3.0