Skip to content

Commit

Permalink
[SPARK-20533][SPARKR] SparkR Wrappers Model should be private and val…
Browse files Browse the repository at this point in the history
…ue should be lazy

## What changes were proposed in this pull request?

MultilayerPerceptronClassifierWrapper model should be private.
LogisticRegressionWrapper.scala rFeatures and rCoefficients should be lazy.

## How was this patch tested?

Unit tests.

Author: wangmiao1981 <[email protected]>

Closes #17808 from wangmiao1981/lazy.
  • Loading branch information
wangmiao1981 authored and Felix Cheung committed Apr 29, 2017
1 parent add9d1b commit ee694cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ private[r] class LogisticRegressionWrapper private (
private val lrModel: LogisticRegressionModel =
pipeline.stages(1).asInstanceOf[LogisticRegressionModel]

val rFeatures: Array[String] = if (lrModel.getFitIntercept) {
lazy val rFeatures: Array[String] = if (lrModel.getFitIntercept) {
Array("(Intercept)") ++ features
} else {
features
}

val rCoefficients: Array[Double] = {
lazy val rCoefficients: Array[Double] = {
val numRows = lrModel.coefficientMatrix.numRows
val numCols = lrModel.coefficientMatrix.numCols
val numColsWithIntercept = if (lrModel.getFitIntercept) numCols + 1 else numCols
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ private[r] class MultilayerPerceptronClassifierWrapper private (

import MultilayerPerceptronClassifierWrapper._

val mlpModel: MultilayerPerceptronClassificationModel =
private val mlpModel: MultilayerPerceptronClassificationModel =
pipeline.stages(1).asInstanceOf[MultilayerPerceptronClassificationModel]

val weights: Array[Double] = mlpModel.weights.toArray
val layers: Array[Int] = mlpModel.layers
lazy val weights: Array[Double] = mlpModel.weights.toArray
lazy val layers: Array[Int] = mlpModel.layers

def transform(dataset: Dataset[_]): DataFrame = {
pipeline.transform(dataset)
Expand Down

0 comments on commit ee694cd

Please sign in to comment.