This topic describes the random forest regression algorithm.

Overview

Random forest regression is an application branch of random forest. The random forest regression model establishes multiple unrelated decision trees by randomly selecting samples and features, and obtains prediction results in parallel. Each decision tree can draw a prediction result by using samples and features. The regression prediction result of the whole forest is obtained by averaging the results of all trees.

Scenarios

Random forest regression can be used in the scenario which requires tens of data dimensions and high accuracy.

For example, the random forest regression model can be used to predict the popularity of a topic on Twitter. The input of the model can be the features of the topic, such as the number of discussion groups for the topic, the number of persons discussing the topic, and the attention of the topic. The output of the model is the average number of active discussion groups per hour. This is a positive floating point number to indicate the popularity.

Parameters

The parameters in the following table are the values of the model_parameter parameters in the CREATE MODEL statement for creating a model. You can select the values based on your needs.

ParameterDescription
n_estimatorsThe number of iterations. A higher number of iterations indicates a better fitting. It is usually a positive integer. The default value is 100.
objectiveThe learning task and its learning objectives. Default value: mse. Valid values:
  • mse: uses the mean squared error.
  • mae: uses the mean absolute error.
max_featuresThe maximum number of features to consider when deciding the partition. Default value: sqrt. Valid values:
  • sqrt: indicates that the maximum number of features is sqrt(n_features).
  • Integer: indicates that the maximum number of features is max_features. The value must range 0 to n_features, with n_features inclusive. The n_features is the number of features used in modeling.
  • Floating point: indicates that the maximum number of features is max_features*n_features.
  • log2: indicates that the maximum number of features is log2(n_features).
random_stateThe random state. This parameter is usually a positive integer. Default value: 1.
n_jobsThe number of parallel threads. A large number indicates a high training speed. This parameter is usually a positive integer. Default value: 4.
max_depthThe maximum depth of each tree. This parameter is usually a positive integer. Default value: None.
Note If this parameter is set to None, the depth of the tree is not specified.

Examples

Create a model and an offline training task.
/*polar4ai*/
CREATE MODEL randomforestreg1 WITH
( model_class = 'randomforestreg', x_cols = 'dx1,dx2', y_cols='y',
 model_parameter=(objective='mse')) AS (select * from db4ai.testdata1)
Use the model for prediction.
/*polar4ai*/
select dx1,dx2 FROM
PREDICT(MODEL randomforestreg1, select * from db4ai.testdata1 limit 10)
WITH (x_cols = 'dx1,dx2', y_cols='')
Note The columns in x_cols and y_cols must use floating-point or integer data.