Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/2378#discussion_r17703595
--- Diff: python/pyspark/mllib/tree.py ---
@@ -90,53 +89,24 @@ class DecisionTree(object):
EXPERIMENTAL: This is an experimental API.
It will probably be modified for Spark v1.2.
- Example usage:
-
- >>> from numpy import array
- >>> import sys
- >>> from pyspark.mllib.regression import LabeledPoint
- >>> from pyspark.mllib.tree import DecisionTree
- >>> from pyspark.mllib.linalg import SparseVector
- >>>
- >>> data = [
- ... LabeledPoint(0.0, [0.0]),
- ... LabeledPoint(1.0, [1.0]),
- ... LabeledPoint(1.0, [2.0]),
- ... LabeledPoint(1.0, [3.0])
- ... ]
- >>> categoricalFeaturesInfo = {} # no categorical features
- >>> model = DecisionTree.trainClassifier(sc.parallelize(data),
numClasses=2,
- ...
categoricalFeaturesInfo=categoricalFeaturesInfo)
- >>> sys.stdout.write(model)
- DecisionTreeModel classifier
- If (feature 0 <= 0.5)
- Predict: 0.0
- Else (feature 0 > 0.5)
- Predict: 1.0
- >>> model.predict(array([1.0])) > 0
- True
- >>> model.predict(array([0.0])) == 0
- True
- >>> sparse_data = [
- ... LabeledPoint(0.0, SparseVector(2, {0: 0.0})),
- ... LabeledPoint(1.0, SparseVector(2, {1: 1.0})),
- ... LabeledPoint(0.0, SparseVector(2, {0: 0.0})),
- ... LabeledPoint(1.0, SparseVector(2, {1: 2.0}))
- ... ]
- >>>
- >>> model = DecisionTree.trainRegressor(sc.parallelize(sparse_data),
- ...
categoricalFeaturesInfo=categoricalFeaturesInfo)
- >>> model.predict(array([0.0, 1.0])) == 1
- True
- >>> model.predict(array([0.0, 0.0])) == 0
- True
- >>> model.predict(SparseVector(2, {1: 1.0})) == 1
- True
- >>> model.predict(SparseVector(2, {1: 0.0})) == 0
- True
"""
@staticmethod
+ def _train(data, type, numClasses, categoricalFeaturesInfo,
+ impurity="gini", maxDepth=5, maxBins=32,
minInstancesPerNode=1,
+ minInfoGain=0.0):
+ first = data.first()
+ assert isinstance(first, LabeledPoint), "the data should be RDD of
LabeleddPoint"
--- End diff --
"LabeleddPoint" --> "LabeledPoint"
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]