Spark ML -- Random Forest
Perform classification and regression using random forests.
ml_random_forest_classifier(x, formula = NULL, num_trees = 20L, subsampling_rate = 1, max_depth = 5L, min_instances_per_node = 1L, feature_subset_strategy = "auto", impurity = "gini", min_info_gain = 0, max_bins = 32L, seed = NULL, thresholds = NULL, checkpoint_interval = 10L, cache_node_ids = FALSE, max_memory_in_mb = 256L, features_col = "features", label_col = "label", prediction_col = "prediction", probability_col = "probability", raw_prediction_col = "rawPrediction", uid = random_string("random_forest_classifier_"), ...)
ml_random_forest(x, formula = NULL, type = c("auto", "regression", "classification"), features_col = "features", label_col = "label", prediction_col = "prediction", probability_col = "probability", raw_prediction_col = "rawPrediction", feature_subset_strategy = "auto", impurity = "auto", checkpoint_interval = 10L, max_bins = 32L, max_depth = 5L, num_trees = 20L, min_info_gain = 0, min_instances_per_node = 1L, subsampling_rate = 1, seed = NULL, thresholds = NULL, cache_node_ids = FALSE, max_memory_in_mb = 256L, uid = random_string("random_forest_"), response = NULL, features = NULL, ...)
ml_random_forest_regressor(x, formula = NULL, num_trees = 20L, subsampling_rate = 1, max_depth = 5L, min_instances_per_node = 1L, feature_subset_strategy = "auto", impurity = "variance", min_info_gain = 0, max_bins = 32L, seed = NULL, checkpoint_interval = 10L, cache_node_ids = FALSE, max_memory_in_mb = 256L, features_col = "features", label_col = "label", prediction_col = "prediction", uid = random_string("random_forest_regressor_"), ...)
ml_pipeline, or a
tbl_spark. R formula as a character string or a formula. This is used to transform the input dataframe before fitting, see ft_r_formula for details.
Number of trees to train (>= 1). If 1, then no bootstrapping is used. If > 1, then bootstrapping is done.
Fraction of the training data used for learning each decision tree, in range (0, 1]. (default = 1.0)
Maximum depth of the tree (>= 0); that is, the maximum number of nodes separating any leaves from the root of the tree.
Minimum number of instances each child must have after split.
The number of features to consider for splits at each tree node. See details for options.
Criterion used for information gain calculation. Supported: "entropy" and "gini" (default) for classification and "variance" (default) for regression. For
"auto"will default to the appropriate criterion based on model type.
Minimum information gain for a split to be considered at a tree node. Should be >= 0, defaults to 0.
The maximum number of bins used for discretizing continuous features and for choosing how to split on features at each node. More bins give higher granularity.
Seed for random numbers.
Thresholds in multi-class classification to adjust the probability of predicting each class. Array must have length equal to the number of classes, with values > 0 excepting that at most one value may be 0. The class with largest value
p/tis predicted, where
pis the original probability of that class and
tis the class's threshold.
Set checkpoint interval (>= 1) or disable checkpoint (-1). E.g. 10 means that the cache will get checkpointed every 10 iterations, defaults to 10.
FALSE, the algorithm will pass trees to executors to match instances with nodes. If
TRUE, the algorithm will cache node IDs for each instance. Caching can speed up training of deeper trees. Defaults to
Maximum memory in MB allocated to histogram aggregation. If too small, then 1 node will be split per iteration, and its aggregates may exceed this size. Defaults to 256.
Features column name, as a length-one character vector. The column should be single vector column of numeric values. Usually this column is output by
Label column name. The column should be a numeric column. Usually this column is output by
Prediction column name.
Column name for predicted class conditional probabilities.
Raw prediction (a.k.a. confidence) column name.
A character string used to uniquely identify the ML estimator.
Optional arguments; see Details.
The type of model to fit.
"regression"treats the response as a continuous variable, while
"classification"treats the response as a categorical variable. When
"auto"is used, the model type is inferred based on the response variable type -- if it is a numeric type, then regression is used; classification otherwise.
(Deprecated) The name of the response column (as a length-one character vector.)
(Deprecated) The name of features (terms) to use for the model fit.
x is a
features) is specified, the function returns a
ml_model object wrapping a
ml_pipeline_model which contains data pre-processing transformers, the ML predictor, and, for classification models, a post-processing transformer that converts predictions into class labels. For classification, an optional argument
predicted_label_col (defaults to
"predicted_label") can be used to specify the name of the predicted label column. In addition to the fitted
ml_model objects also contain a
ml_pipeline object where the ML predictor stage is an estimator ready to be fit against data. This is utilized by
type = "pipeline" to faciliate model refresh workflows.
The supported options for
"auto": Choose automatically for task: If
num_trees == 1, set to
num_trees > 1(forest), set to
"sqrt"for classification and to
"all": use all features
"onethird": use 1/3 of the features
"sqrt": use use sqrt(number of features)
"log2": use log2(number of features)
nis in the range (0, 1.0], use n * number of features. When
nis in the range (1, number of features), use
nfeatures. (default =
ml_random_forest is a wrapper around
ml_random_forest_classifier.tbl_spark and calls the appropriate method based on model type.
The object returned depends on the class of
spark_connection, the function returns an instance of a
ml_predictorobject. The object contains a pointer to a Spark
Predictorobject and can be used to compose
ml_pipeline, the function returns a
ml_pipelinewith the predictor appended to the pipeline.
tbl_spark, a predictor is constructed then immediately fit with the input
tbl_spark, returning a prediction model.
formula: specified When
formulais specified, the input
tbl_sparkis first transformed using a
RFormulatransformer before being fit by the predictor. The object returned in this case is a
ml_modelwhich is a wrapper of a
See http://spark.apache.org/docs/latest/ml-classification-regression.html for more information on the set of supervised learning algorithms.
Other ml algorithms: