Github user thunterdb commented on a diff in the pull request: https://github.com/apache/spark/pull/9936#discussion_r49143733 --- 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 + sqlContext = SQLContext(self.sc) + self.df = sqlContext.createDataFrame([ + (1.0, Vectors.dense(1.0, 0.0)), + (0.0, Vectors.sparse(2, [1], [1.0]))], ["label", "features"]) + + def test_logistic_regression(self): + self.setupData() + lr = LogisticRegression(maxIter=5, regParam=0.01) + model = lr.fit(self.df) + self.assertEqual(2, model.numFeatures) + + def test_decision_tree_classifier(self): + from pyspark.ml.feature import StringIndexer --- End diff -- same thing here
--- 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