Github user yanboliang commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15883#discussion_r87829586
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/r/MultilayerPerceptronClassifierWrapper.scala
 ---
    @@ -73,25 +90,25 @@ private[r] object MultilayerPerceptronClassifierWrapper
           .setMaxIter(maxIter)
           .setTol(tol)
           .setStepSize(stepSize)
    -      .setPredictionCol(PREDICTED_LABEL_COL)
    +      .setFeaturesCol(rFormula.getFeaturesCol)
    +      .setLabelCol(rFormula.getLabelCol)
    +      .setPredictionCol(PREDICTED_LABEL_INDEX_COL)
         if (seed != null && seed.length > 0) mlp.setSeed(seed.toInt)
         if (initialWeights != null) {
           require(initialWeights.length > 0)
           mlp.setInitialWeights(Vectors.dense(initialWeights))
         }
     
    +    val idxToStr = new IndexToString()
    +      .setInputCol(PREDICTED_LABEL_INDEX_COL)
    +      .setOutputCol(PREDICTED_LABEL_COL)
    +      .setLabels(labels)
    +
         val pipeline = new Pipeline()
    -      .setStages(Array(mlp))
    +      .setStages(Array(rFormulaModel, mlp, idxToStr))
           .fit(data)
     
    -    val multilayerPerceptronClassificationModel: 
MultilayerPerceptronClassificationModel =
    -    
pipeline.stages.head.asInstanceOf[MultilayerPerceptronClassificationModel]
    -
    -    val weights = multilayerPerceptronClassificationModel.weights.toArray
    -    val layersFromPipeline = multilayerPerceptronClassificationModel.layers
    -    val labelCount = data.select("label").distinct().count()
    --- End diff --
    
    ```weights``` and ```layers``` can be get from the MLP model, so it's not 
necessary to store them. It's also not necessary to calculate ```labelCount``` 
by ```distinct``` which is very expensive. Actually we can get ```labelCount``` 
from the member variable ```layers``` of MLP model.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to