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

    https://github.com/apache/spark/pull/3320#discussion_r20676259
  
    --- Diff: python/pyspark/mllib/tree.py ---
    @@ -181,8 +182,206 @@ def trainRegressor(data, categoricalFeaturesInfo,
             >>> model.predict(rdd).collect()
             [1.0, 0.0]
             """
    -        return DecisionTree._train(data, "regression", 0, 
categoricalFeaturesInfo,
    -                                   impurity, maxDepth, maxBins, 
minInstancesPerNode, minInfoGain)
    +        return cls._train(data, "regression", 0, categoricalFeaturesInfo,
    +                          impurity, maxDepth, maxBins, 
minInstancesPerNode, minInfoGain)
    +
    +
    +class RandomForestModel(JavaModelWrapper):
    +    """
    +    Represents a random forest model.
    +
    +    EXPERIMENTAL: This is an experimental API.
    +                  It will probably be modified in future.
    +    """
    +    def predict(self, x):
    +        """
    +        Predict values for a single data point or an RDD of points using
    +        the model trained.
    +        """
    +        if isinstance(x, RDD):
    +            return self.call("predict", x.map(_convert_to_vector))
    +
    +        else:
    +            return self.call("predict", _convert_to_vector(x))
    +
    +    def numTrees(self):
    +        """
    +        Get number of trees in forest.
    +        """
    +        return self.call("numTrees")
    +
    +    def totalNumNodes(self):
    +        """
    +        Get total number of nodes, summed over all trees in the forest.
    +        """
    +        return self.call("totalNumNodes")
    +
    +    def __repr__(self):
    +        """ Summary of model """
    +        return self._java_model.toString()
    +
    +    def toDebugString(self):
    +        """ Full model """
    +        return self._java_model.toDebugString()
    +
    +
    +class RandomForest(object):
    +    """
    +    Learning algorithm for a random forest model for classification or 
regression.
    +
    +    EXPERIMENTAL: This is an experimental API.
    +                  It will probably be modified in future.
    +    """
    +
    +    supportedFeatureSubsetStrategies = ("auto", "all", "sqrt", "log2", 
"onethird")
    +
    +    @classmethod
    +    def _train(cls, data, type, numClasses, features, impurity, maxDepth, 
maxBins,
    +               numTrees, featureSubsetStrategy, seed):
    +        first = data.first()
    +        assert isinstance(first, LabeledPoint), "the data should be RDD of 
LabeledPoint"
    +        if featureSubsetStrategy not in 
cls.supportedFeatureSubsetStrategies:
    +            raise ValueError("unsupported featureSubsetStrategy: %s" % 
featureSubsetStrategy)
    +        if seed is None:
    +            seed = random.randint(0, 1 << 30)
    +        model = callMLlibFunc("trainRandomForestModel", data, type, 
numClasses, features,
    +                              impurity, maxDepth, maxBins, numTrees, 
featureSubsetStrategy, seed)
    +        return RandomForestModel(model)
    +
    +    @classmethod
    +    def trainClassifier(cls, data, numClassesForClassification, 
categoricalFeaturesInfo, numTrees,
    +                        featureSubsetStrategy="auto", impurity="gini", 
maxDepth=4, maxBins=32,
    +                        seed=None):
    +        """
    +        Method to train a decision tree model for binary or multiclass
    +        classification.
    +
    +        :param data: Training dataset: RDD of LabeledPoint. Labels should 
take
    +               values {0, 1, ..., numClasses-1}.
    +        :param numClassesForClassification: number of classes for 
classification.
    +        :param categoricalFeaturesInfo: Map storing arity of categorical 
features.
    +               E.g., an entry (n -> k) indicates that feature n is 
categorical
    +               with k categories indexed from 0: {0, 1, ..., k-1}.
    +        :param numTrees: Number of trees in the random forest.
    +        :param featureSubsetStrategy: Number of features to consider for 
splits at
    +               each node.
    +               Supported: "auto" (default), "all", "sqrt", "log2", 
"onethird".
    +               If "auto" is set, this parameter is set based on numTrees:
    +               if numTrees == 1, set to "all";
    +               if numTrees > 1 (forest) set to "sqrt" for classification 
and to
    --- End diff --
    
    could just state default for classification


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