Skip to content
Snippets Groups Projects
Commit ee694cdf authored by wangmiao1981's avatar wangmiao1981 Committed by Felix Cheung
Browse files

[SPARK-20533][SPARKR] SparkR Wrappers Model should be private and value 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 <wm624@hotmail.com>

Closes #17808 from wangmiao1981/lazy.
parent add9d1bb
No related branches found
No related tags found
No related merge requests found
...@@ -40,13 +40,13 @@ private[r] class LogisticRegressionWrapper private ( ...@@ -40,13 +40,13 @@ private[r] class LogisticRegressionWrapper private (
private val lrModel: LogisticRegressionModel = private val lrModel: LogisticRegressionModel =
pipeline.stages(1).asInstanceOf[LogisticRegressionModel] pipeline.stages(1).asInstanceOf[LogisticRegressionModel]
val rFeatures: Array[String] = if (lrModel.getFitIntercept) { lazy val rFeatures: Array[String] = if (lrModel.getFitIntercept) {
Array("(Intercept)") ++ features Array("(Intercept)") ++ features
} else { } else {
features features
} }
val rCoefficients: Array[Double] = { lazy val rCoefficients: Array[Double] = {
val numRows = lrModel.coefficientMatrix.numRows val numRows = lrModel.coefficientMatrix.numRows
val numCols = lrModel.coefficientMatrix.numCols val numCols = lrModel.coefficientMatrix.numCols
val numColsWithIntercept = if (lrModel.getFitIntercept) numCols + 1 else numCols val numColsWithIntercept = if (lrModel.getFitIntercept) numCols + 1 else numCols
......
...@@ -36,11 +36,11 @@ private[r] class MultilayerPerceptronClassifierWrapper private ( ...@@ -36,11 +36,11 @@ private[r] class MultilayerPerceptronClassifierWrapper private (
import MultilayerPerceptronClassifierWrapper._ import MultilayerPerceptronClassifierWrapper._
val mlpModel: MultilayerPerceptronClassificationModel = private val mlpModel: MultilayerPerceptronClassificationModel =
pipeline.stages(1).asInstanceOf[MultilayerPerceptronClassificationModel] pipeline.stages(1).asInstanceOf[MultilayerPerceptronClassificationModel]
val weights: Array[Double] = mlpModel.weights.toArray lazy val weights: Array[Double] = mlpModel.weights.toArray
val layers: Array[Int] = mlpModel.layers lazy val layers: Array[Int] = mlpModel.layers
def transform(dataset: Dataset[_]): DataFrame = { def transform(dataset: Dataset[_]): DataFrame = {
pipeline.transform(dataset) pipeline.transform(dataset)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment