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

    https://github.com/apache/spark/pull/15721#discussion_r93762341
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/util/MLTestingUtils.scala ---
    @@ -224,4 +208,59 @@ object MLTestingUtils extends SparkFunSuite {
         }.toDF()
         (overSampledData, weightedData)
       }
    +
    +  /**
    +   * Helper function for testing sample weights. Tests that oversampling 
each point is equivalent
    +   * to assigning a sample weight proportional to the number of samples 
for each point.
    +   */
    +  def testOversamplingVsWeighting[M <: Model[M], E <: Estimator[M]](
    +      df: DataFrame,
    +      estimator: E with HasWeightCol with HasLabelCol with HasFeaturesCol,
    +      modelEquals: (M, M) => Unit,
    +      seed: Long): Unit = {
    +    val (overSampledData, weightedData) = 
genEquivalentOversampledAndWeightedInstances(
    +      df, estimator.getLabelCol, estimator.getFeaturesCol, seed)
    +    val weightedModel = estimator.set(estimator.weightCol, 
"weight").fit(weightedData)
    +    val overSampledModel = estimator.set(estimator.weightCol, 
"").fit(overSampledData)
    +    modelEquals(weightedModel, overSampledModel)
    +  }
    +
    +  /**
    +   * Helper function for testing sample weights. Tests that injecting a 
large number of outliers
    +   * with very small sample weights does not affect fitting. The predictor 
should learn the true
    +   * model despite the outliers.
    +   */
    +  def testOutliersWithSmallWeights[M <: Model[M], E <: Estimator[M]](
    +      ds: Dataset[Instance],
    --- End diff --
    
    I'd prefer to change this to ```data: Dataset[LabeledPoint]```(pass in 
dataset w/o weight), and move ```.withColumn("weight", lit(1.0))```(which are 
duplicated in test cases of each algorithms currently) inside this function.


---
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