PREDICT_RF_CLASSIFIER

Applies a random forest model on an input relation. The predicted class is selected only based on the popular vote of the decision trees in the forest. Therefore, in special cases the calculated probability of the predicted class may not be the highest.

Syntax

PREDICT_RF_CLASSIFIER ( input‑columns
                       USING PARAMETERS model_name='model‑name'
                                        [, type='prediction‑type']                  
                                        [, class='user‑input‑class']
                                        [, match_by_pos=match‑by‑position] ) 

Arguments

input‑columns Comma-separated list of columns to use from the input relation, or asterisk (*) to select all columns.

Parameter Settings

Parameter name Set to…
model_name Name of the model (case-insensitive)
type

Type of prediction to return, one of the following:

  • response (default): The class with the highest probability among all possible classes.
  • probability: Valid only if the class parameter is set, returns the probability of the specified class.
class

Class to use when the type parameter is set to probability. If you omit this parameter, the function uses the predicted class—the one with popular vote. Thus, the predict function returns the probability that the input instance belongs to its predicted class.

Default: Auto

match_by_pos

Boolean value that specifies how input columns are matched to model features:

  • false (default): Match by name.

  • true: Match by the position of columns in the input columns list.

Returns

VARCHAR data type that specifies one of the following, as determined by how the type parameter is set:

  • The predicted class (based on popular votes)
  • Probability of a class for each input instance.

Examples

=> SELECT PREDICT_RF_CLASSIFIER (Sepal_Length, Sepal_Width, Petal_Length, Petal_Width
                                  USING PARAMETERS model_name='myRFModel') FROM iris;
PREDICT_RF_CLASSIFIER
-----------------------
setosa
setosa
setosa
…
versicolor
versicolor
versicolor
…
virginica
virginica
virginica
…
(150 rows)

This example shows how you can use the PREDICT_RF_CLASSIFIER function, using the match_by_pos parameter:

=> SELECT PREDICT_RF_CLASSIFIER (Sepal_Length, Sepal_Width, Petal_Length, Petal_Width
                                USING PARAMETERS model_name='myRFModel', match_by_pos='true') FROM iris;
PREDICT_RF_CLASSIFIER
-----------------------
setosa
setosa
setosa
…
versicolor
versicolor
versicolor
…
virginica
virginica
virginica
…
(150 rows)

See Also