You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by thunterdb <gi...@git.apache.org> on 2016/01/08 01:00:37 UTC

[GitHub] spark pull request: [SPARK-11938][ML] Expose numFeatures in all ML...

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

    https://github.com/apache/spark/pull/9936#discussion_r49143685
  
    --- Diff: python/pyspark/ml/tests.py ---
    @@ -371,6 +378,103 @@ def test_fit_maximize_metric(self):
             self.assertEqual(1.0, bestModelMetric, "Best model has R-squared of 1")
     
     
    +class RegressorTest(PySparkTestCase):
    +
    +    def setupData(self):
    +        try:
    +            self.df
    +        except AttributeError:
    +            from pyspark.mllib.linalg import Vectors
    +            sqlContext = SQLContext(self.sc)
    +            self.df = sqlContext.createDataFrame([
    +                (1.0, Vectors.dense(1.0)),
    +                (0.0, Vectors.sparse(1, [], []))], ["label", "features"])
    +
    +    def test_linear_regression(self):
    +        self.setupData()
    +        lr = LinearRegression(maxIter=5, regParam=0.0, solver="normal")
    +        model = lr.fit(self.df)
    +        self.assertEquals(1, model.numFeatures)
    +
    +    def test_decision_tree_regressor(self):
    +        self.setupData()
    +        dt = DecisionTreeRegressor(maxDepth=2)
    +        model = dt.fit(self.df)
    +        self.assertEquals(1, model.numFeatures)
    +
    +    def test_random_forest_regressor(self):
    +        self.setupData()
    +        rf = RandomForestRegressor(numTrees=2, maxDepth=2, seed=42)
    +        model = rf.fit(self.df)
    +        self.assertEquals(1, model.numFeatures)
    +
    +    def test_gbt_regressor(self):
    +        self.setupData()
    +        gbt = GBTRegressor(maxIter=5, maxDepth=2)
    +        model = gbt.fit(self.df)
    +        self.assertEquals(1, model.numFeatures)
    +
    +
    +class ClassificationTest(PySparkTestCase):
    +
    +    def setupData(self):
    +        try:
    +            self.df
    +        except AttributeError:
    +            from pyspark.mllib.linalg import Vectors
    --- End diff --
    
    is there any reason for putting the import in the code?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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