Skip to content

Commit

Permalink
[MINOR][ML] When trainingSummary is None, it should throw RuntimeExce…
Browse files Browse the repository at this point in the history
…ption.

## 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 apache#11784 from yanboliang/fix-summary.
  • Loading branch information
yanboliang authored and roygao94 committed Mar 22, 2016
1 parent a92ad3b commit b6c435f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit b6c435f

Please sign in to comment.