Feedback:

fit LinearRegression

Use the LinearRegression algorithm when you want to explore how one or more independent variables relate to a dependent variable, by fitting a model that predicts the value of numeric fields and evaluating the fit of the regression model.

Furthermore, you can also use the Linear Regression Visualization Type, on the AQL Search page, to visualize the results of your regression model.

Syntax

fit LinearRegression [option_name]=[option_value]... <field_to_predict> from <explanatory_fields> [kfold_cv=n] [into '<model_name>']

[option_name]=[value]

(Optional) Specify model parameters:

  • fit_intercept={true|false}

  • Positive={true|false}

For information on the model parameters, refer to scikit learn documentation:

https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html

<field_to_predict> Specify the target field name.
<explanatory_fields> Specify input fields used to train the model.
[kfold_cv=n]

(Optional) Specify this option to support kfold validation. When specified, the validation result will be returned. Substitute a number of folds for n. The number of folds must be at least 2.

Note: This option cannot be used together with into option to save the model.

into (Optional) Specify the into keyword to store the learned model in an artifact that can later be applied to new search results with the apply operator.
'<model_name>'

Specify the name of the model to save as an artifact, so that it can be used with the apply operator. The model name must be wrapped with single or double straight quotation marks.

Usage

You can use the LinearRegression algorithm to fit a model that predicts the value of numeric fields. The input training data has to be preprocessed, encoded, and normalized if required before passing to the fit operator. This algorithm supports the kfold cross-validation option.

Examples

Example 1: Visualize single-variable linear regression

Copy
| fit OrdinalEncoder action src | fit LinearRegression encoded_action from encoded_src into 'linear_regression_model'

Example 2: Visualize single-variable linear regression with residuals

Copy
| fit OrdinalEncoder action src | fit LinearRegression encoded_action from encoded_src into 'linear_regression_model2' with_residuals=true

Example 3: Visualize multiple linear regression

Copy
| fit OrdinalEncoder action src src_port | fit LinearRegression encoded_action from encoded_src encoded_src_port into 'linear_regression_model3'