Class RandomForestClassificationModel

All Implemented Interfaces:
Serializable, org.apache.spark.internal.Logging, org.apache.spark.ml.classification.ClassifierParams, org.apache.spark.ml.classification.ProbabilisticClassifierParams, Params, HasCheckpointInterval, HasFeaturesCol, HasLabelCol, HasPredictionCol, HasProbabilityCol, HasRawPredictionCol, HasSeed, HasThresholds, HasWeightCol, org.apache.spark.ml.PredictorParams, org.apache.spark.ml.tree.DecisionTreeParams, org.apache.spark.ml.tree.RandomForestClassifierParams, org.apache.spark.ml.tree.RandomForestParams, org.apache.spark.ml.tree.TreeClassifierParams, org.apache.spark.ml.tree.TreeEnsembleClassifierParams, org.apache.spark.ml.tree.TreeEnsembleModel<DecisionTreeClassificationModel>, org.apache.spark.ml.tree.TreeEnsembleParams, org.apache.spark.ml.util.HasTrainingSummary<RandomForestClassificationTrainingSummary>, Identifiable, MLWritable

public class RandomForestClassificationModel extends ProbabilisticClassificationModel<Vector,RandomForestClassificationModel> implements org.apache.spark.ml.tree.RandomForestClassifierParams, org.apache.spark.ml.tree.TreeEnsembleModel<DecisionTreeClassificationModel>, MLWritable, Serializable, org.apache.spark.ml.util.HasTrainingSummary<RandomForestClassificationTrainingSummary>
Random Forest model for classification. It supports both binary and multiclass labels, as well as both continuous and categorical features.

param: _trees Decision trees in the ensemble. Warning: These have null parents.

See Also:
  • Method Details

    • read

    • load

      public static RandomForestClassificationModel load(String path)
    • totalNumNodes

      public int totalNumNodes()
      Specified by:
      totalNumNodes in interface org.apache.spark.ml.tree.TreeEnsembleModel<DecisionTreeClassificationModel>
    • impurity

      public final Param<String> impurity()
      Specified by:
      impurity in interface org.apache.spark.ml.tree.TreeClassifierParams
    • numTrees

      public final IntParam numTrees()
      Specified by:
      numTrees in interface org.apache.spark.ml.tree.RandomForestParams
    • bootstrap

      public final BooleanParam bootstrap()
      Specified by:
      bootstrap in interface org.apache.spark.ml.tree.RandomForestParams
    • subsamplingRate

      public final DoubleParam subsamplingRate()
      Specified by:
      subsamplingRate in interface org.apache.spark.ml.tree.TreeEnsembleParams
    • featureSubsetStrategy

      public final Param<String> featureSubsetStrategy()
      Specified by:
      featureSubsetStrategy in interface org.apache.spark.ml.tree.TreeEnsembleParams
    • leafCol

      public final Param<String> leafCol()
      Specified by:
      leafCol in interface org.apache.spark.ml.tree.DecisionTreeParams
    • maxDepth

      public final IntParam maxDepth()
      Specified by:
      maxDepth in interface org.apache.spark.ml.tree.DecisionTreeParams
    • maxBins

      public final IntParam maxBins()
      Specified by:
      maxBins in interface org.apache.spark.ml.tree.DecisionTreeParams
    • minInstancesPerNode

      public final IntParam minInstancesPerNode()
      Specified by:
      minInstancesPerNode in interface org.apache.spark.ml.tree.DecisionTreeParams
    • minWeightFractionPerNode

      public final DoubleParam minWeightFractionPerNode()
      Specified by:
      minWeightFractionPerNode in interface org.apache.spark.ml.tree.DecisionTreeParams
    • minInfoGain

      public final DoubleParam minInfoGain()
      Specified by:
      minInfoGain in interface org.apache.spark.ml.tree.DecisionTreeParams
    • maxMemoryInMB

      public final IntParam maxMemoryInMB()
      Specified by:
      maxMemoryInMB in interface org.apache.spark.ml.tree.DecisionTreeParams
    • cacheNodeIds

      public final BooleanParam cacheNodeIds()
      Specified by:
      cacheNodeIds in interface org.apache.spark.ml.tree.DecisionTreeParams
    • weightCol

      public final Param<String> weightCol()
      Description copied from interface: HasWeightCol
      Param for weight column name. If this is not set or empty, we treat all instance weights as 1.0.
      Specified by:
      weightCol in interface HasWeightCol
      Returns:
      (undocumented)
    • seed

      public final LongParam seed()
      Description copied from interface: HasSeed
      Param for random seed.
      Specified by:
      seed in interface HasSeed
      Returns:
      (undocumented)
    • checkpointInterval

      public final IntParam checkpointInterval()
      Description copied from interface: HasCheckpointInterval
      Param for set checkpoint interval (&gt;= 1) or disable checkpoint (-1). E.g. 10 means that the cache will get checkpointed every 10 iterations. Note: this setting will be ignored if the checkpoint directory is not set in the SparkContext.
      Specified by:
      checkpointInterval in interface HasCheckpointInterval
      Returns:
      (undocumented)
    • uid

      public String uid()
      Description copied from interface: Identifiable
      An immutable unique ID for the object and its derivatives.
      Specified by:
      uid in interface Identifiable
      Returns:
      (undocumented)
    • numFeatures

      public int numFeatures()
      Description copied from class: PredictionModel
      Returns the number of features the model was trained on. If unknown, returns -1
      Overrides:
      numFeatures in class PredictionModel<Vector,RandomForestClassificationModel>
    • numClasses

      public int numClasses()
      Description copied from class: ClassificationModel
      Number of classes (values which the label can take).
      Specified by:
      numClasses in class ClassificationModel<Vector,RandomForestClassificationModel>
    • trees

      Specified by:
      trees in interface org.apache.spark.ml.tree.TreeEnsembleModel<DecisionTreeClassificationModel>
    • treeWeights

      public double[] treeWeights()
      Specified by:
      treeWeights in interface org.apache.spark.ml.tree.TreeEnsembleModel<DecisionTreeClassificationModel>
    • summary

      Gets summary of model on training set. An exception is thrown if hasSummary is false.
      Specified by:
      summary in interface org.apache.spark.ml.util.HasTrainingSummary<RandomForestClassificationTrainingSummary>
      Returns:
      (undocumented)
    • binarySummary

      Gets summary of model on training set. An exception is thrown if hasSummary is false or it is a multiclass model.
      Returns:
      (undocumented)
    • evaluate

      public RandomForestClassificationSummary evaluate(Dataset<?> dataset)
      Evaluates the model on a test dataset.

      Parameters:
      dataset - Test dataset to evaluate model on.
      Returns:
      (undocumented)
    • transformSchema

      public StructType transformSchema(StructType schema)
      Description copied from class: PipelineStage
      Check transform validity and derive the output schema from the input schema.

      We check validity for interactions between parameters during transformSchema and raise an exception if any parameter value is invalid. Parameter value checks which do not depend on other parameters are handled by Param.validate().

      Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks.

      Overrides:
      transformSchema in class ProbabilisticClassificationModel<Vector,RandomForestClassificationModel>
      Parameters:
      schema - (undocumented)
      Returns:
      (undocumented)
    • transform

      public Dataset<Row> transform(Dataset<?> dataset)
      Description copied from class: ProbabilisticClassificationModel
      Transforms dataset by reading from PredictionModel.featuresCol(), and appending new columns as specified by parameters: - predicted labels as PredictionModel.predictionCol() of type Double - raw predictions (confidences) as ClassificationModel.rawPredictionCol() of type Vector - probability of each class as ProbabilisticClassificationModel.probabilityCol() of type Vector.

      Overrides:
      transform in class ProbabilisticClassificationModel<Vector,RandomForestClassificationModel>
      Parameters:
      dataset - input dataset
      Returns:
      transformed dataset
    • predictRaw

      public Vector predictRaw(Vector features)
      Description copied from class: ClassificationModel
      Raw prediction for each possible label. The meaning of a "raw" prediction may vary between algorithms, but it intuitively gives a measure of confidence in each possible label (where larger = more confident). This internal method is used to implement transform() and output ClassificationModel.rawPredictionCol().

      Specified by:
      predictRaw in class ClassificationModel<Vector,RandomForestClassificationModel>
      Parameters:
      features - (undocumented)
      Returns:
      vector where element i is the raw prediction for label i. This raw prediction may be any real number, where a larger value indicates greater confidence for that label.
    • copy

      Description copied from interface: Params
      Creates a copy of this instance with the same UID and some extra params. Subclasses should implement this method and set the return type properly. See defaultCopy().
      Specified by:
      copy in interface Params
      Specified by:
      copy in class Model<RandomForestClassificationModel>
      Parameters:
      extra - (undocumented)
      Returns:
      (undocumented)
    • toString

      public String toString()
      Specified by:
      toString in interface Identifiable
      Specified by:
      toString in interface org.apache.spark.ml.tree.TreeEnsembleModel<DecisionTreeClassificationModel>
      Overrides:
      toString in class Object
    • featureImportances

      public Vector featureImportances()
    • write

      public MLWriter write()
      Description copied from interface: MLWritable
      Returns an MLWriter instance for this ML instance.
      Specified by:
      write in interface MLWritable
      Returns:
      (undocumented)