diff options
author | Yanbo Liang <ybliang8@gmail.com> | 2016-03-18 11:23:17 +0000 |
---|---|---|
committer | Sean Owen <sowen@cloudera.com> | 2016-03-18 11:23:17 +0000 |
commit | 7783b6f38ffb320050e1c826134187cd0f29ee9b (patch) | |
tree | fb28bd8499716f5a8fb885a1dec51221de398ab7 /mllib | |
parent | bb1fda01fe620422c442b305f5ceeb552871a490 (diff) | |
download | spark-7783b6f38ffb320050e1c826134187cd0f29ee9b.tar.gz spark-7783b6f38ffb320050e1c826134187cd0f29ee9b.tar.bz2 spark-7783b6f38ffb320050e1c826134187cd0f29ee9b.zip |
[MINOR][ML] When trainingSummary is None, it should throw RuntimeException.
## What changes were proposed in this pull request?
When trainingSummary is None, it should throw ```RuntimeException```.
cc mengxr
## How was this patch tested?
Existing tests.
Author: Yanbo Liang <ybliang8@gmail.com>
Closes #11784 from yanboliang/fix-summary.
Diffstat (limited to 'mllib')
4 files changed, 8 insertions, 20 deletions
diff --git a/mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala b/mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala index 77e59d9188..861b1d4b66 100644 --- a/mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala +++ b/mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala @@ -509,12 +509,8 @@ class LogisticRegressionModel private[spark] ( * thrown if `trainingSummary == None`. */ @Since("1.5.0") - def summary: LogisticRegressionTrainingSummary = trainingSummary match { - case Some(summ) => summ - case None => - throw new SparkException( - "No training summary available for this LogisticRegressionModel", - new NullPointerException()) + def summary: LogisticRegressionTrainingSummary = trainingSummary.getOrElse { + throw new SparkException("No training summary available for this LogisticRegressionModel") } /** diff --git a/mllib/src/main/scala/org/apache/spark/ml/clustering/KMeans.scala b/mllib/src/main/scala/org/apache/spark/ml/clustering/KMeans.scala index ab00127899..38428826a8 100644 --- a/mllib/src/main/scala/org/apache/spark/ml/clustering/KMeans.scala +++ b/mllib/src/main/scala/org/apache/spark/ml/clustering/KMeans.scala @@ -148,12 +148,9 @@ class KMeansModel private[ml] ( * thrown if `trainingSummary == None`. */ @Since("2.0.0") - def summary: KMeansSummary = trainingSummary match { - case Some(summ) => summ - case None => - throw new SparkException( - s"No training summary available for the ${this.getClass.getSimpleName}", - new NullPointerException()) + def summary: KMeansSummary = trainingSummary.getOrElse { + throw new SparkException( + s"No training summary available for the ${this.getClass.getSimpleName}") } } diff --git a/mllib/src/main/scala/org/apache/spark/ml/regression/GeneralizedLinearRegression.scala b/mllib/src/main/scala/org/apache/spark/ml/regression/GeneralizedLinearRegression.scala index 6e74cb54ad..0e71e8d8e1 100644 --- a/mllib/src/main/scala/org/apache/spark/ml/regression/GeneralizedLinearRegression.scala +++ b/mllib/src/main/scala/org/apache/spark/ml/regression/GeneralizedLinearRegression.scala @@ -681,8 +681,7 @@ class GeneralizedLinearRegressionModel private[ml] ( @Since("2.0.0") def summary: GeneralizedLinearRegressionSummary = trainingSummary.getOrElse { throw new SparkException( - "No training summary available for this GeneralizedLinearRegressionModel", - new RuntimeException()) + "No training summary available for this GeneralizedLinearRegressionModel") } private[regression] def setSummary(summary: GeneralizedLinearRegressionSummary): this.type = { diff --git a/mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala b/mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala index c8f3f70a9b..b81c588e44 100644 --- a/mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala +++ b/mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala @@ -398,12 +398,8 @@ class LinearRegressionModel private[ml] ( * thrown if `trainingSummary == None`. */ @Since("1.5.0") - def summary: LinearRegressionTrainingSummary = trainingSummary match { - case Some(summ) => summ - case None => - throw new SparkException( - "No training summary available for this LinearRegressionModel", - new NullPointerException()) + def summary: LinearRegressionTrainingSummary = trainingSummary.getOrElse { + throw new SparkException("No training summary available for this LinearRegressionModel") } private[regression] def setSummary(summary: LinearRegressionTrainingSummary): this.type = { |