rforest
Uses a random forest model (an ensemble method that randomly trains multiple decision trees) to predict classification values for input data.
Command properties
| Item | Description |
|---|---|
| Command type | Processing query |
| Required permission | None |
| License usage | N/A |
| Parallel execution | Not supported |
| Distributed execution | Runs on Control Node (reducer) |
Syntax
To predict using a pre-trained model:
To train on data from a subquery and then predict:
In the syntax above, scorer is available starting with 4.0.2609.0.
Options
model=STR- Name of the random forest model. Machine learning models can be created and trained through the Logpresso Sonar web console or shell.
target=STR- Target field name. Specifies the field to use as the prediction target in random forest classification.
timeout=INT{s|m|h|d}- Subquery execution time limit. If the subquery does not complete within the specified time, it is cancelled.
scorer=INT- Assigns the top N fields that most influenced the prediction to the
_scoreroutput field. If omitted, the_scorerfield is not output. Applies to both predictions that use themodeloption and subquery-based training predictions. Available starting with 4.0.2609.0.
Target
FIELD, ...- List of feature fields to use for random forest analysis, separated by commas (
,). Field values can be numbers, dates, IP addresses, or strings. String values are internally encoded for processing. [ SUBQUERY ]- Subquery that retrieves training data. The random forest model is built using the subquery results, then predictions are made for input records.
Output fields
| Field | Type | Description |
|---|---|---|
| _guess | string | Predicted classification value of the target field |
| _rforest_error | string | In subquery mode, contains the error message if an error occurs during training |
| _scorer | array | When scorer is specified, contains the top N fields that most influenced the prediction and their contribution counts, in [[field, count], ...] format. The contribution count is the number of times the field was used in a decision tree split; only fields with a count greater than 0 are included, so the array can be shorter than N. Available starting with 4.0.2609.0, which has the scorer option; not output in the 5.0 series (through 5.0.2605.2). |
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
| 40804 | check-ml-license | No machine learning license |
| 41100 | model option is empty | The model option value is empty |
| 41101 | model not found | A model with the specified name does not exist |
| 41102 | model handler not found | The model handler cannot be found |
| 41103 | scorer option must be a positive integer | The scorer option value is 0 or less, or not an integer. Available starting with 4.0.2609.0, which has the scorer option. |
| 90204 | sqbracket-mismatch | Subquery brackets are not properly paired |
| 90206 | invalid-subquery | No subquery is specified and no model option is given |
Runtime errors
N/A
Description
The rforest command uses the random forest algorithm to predict the target field value for input records. Random forest is an ensemble learning method that randomly constructs multiple decision trees and combines each tree's prediction to produce the final classification.
Two modes are available:
- Pre-trained model: Specify a pre-trained model with the
modeloption. Input records are passed directly to the model and prediction results are assigned to the_guessfield. - Subquery training: Specify the
targetoption and a subquery. The random forest model is first trained on the subquery results, then predictions are made for input records.
The number of decision trees in the forest is fixed at 100 and cannot be changed from a query.
Feature field values of null are treated as missing values. String values are internally encoded as integers for training and prediction.
When you specify the scorer option, the command also outputs the top N fields among those used for prediction that most influenced the result, as an array in the _scorer field using [[field, count], ...] format. The count is the number of times the field was used in a decision tree split; only fields with a count greater than 0 are included, so the array can be shorter than N.
In a distributed environment, model training and prediction are performed on the Control Node.
Examples
-
Predicting with a pre-trained model
table duration=1d test_data | rforest model=rforest_titanicUses the pre-trained
rforest_titanicmodel to predict classification values for input data. -
Training with a subquery and analyzing top contributing fields (4.0 series, 4.0.2609.0 and later)
csvfile /opt/logpresso/titanic_test.csv | rforest scorer=2 target=Survived Pclass, Sex, Age, Fare, Embarked [ csvfile /opt/logpresso/titanic_train.csv | eval Age = double(Age), Fare = double(Fare) ]Trains the model on data from
titanic_train.csvand predicts theSurvivedfield value for data intitanic_test.csv, while usingscorer=2to assign the top 2 fields that most influenced each prediction to the_scorerfield. -
Training and predicting with a subquery
csvfile /opt/logpresso/titanic_test.csv | rforest target=Survived Pclass, Sex, Age, Fare, Embarked [ csvfile /opt/logpresso/titanic_train.csv | eval Age = double(Age), Fare = double(Fare) ]Trains the model on data from
titanic_train.csvand predicts theSurvivedfield value for data intitanic_test.csv. -
Training with a subquery using a timeout
table duration=1d test_data | rforest timeout=30s target=category feature1, feature2, feature3 [ table duration=30d training_data ]Limits the subquery execution time to 30 seconds to retrieve training data and predicts the
categoryfield value. -
Analyzing top contributing fields with a pre-trained model (4.0 series, 4.0.2609.0 and later)
table duration=1d test_data | rforest scorer=2 model=rforest_titanicUses the pre-trained
rforest_titanicmodel to predict, and usesscorer=2to assign the top 2 fields that most influenced each prediction to the_scorerfield.
Change history
| Target | Introduced in |
|---|---|
The rforest command | Before Sonar 4.0 |
The scorer option | 4.0.2609.0 |