curvefit
Performs linear regression to calculate the polynomial curve that best fits the input data. Uses the least squares method to estimate a polynomial function between the independent and dependent variables.
Command properties
| Item | Description |
|---|---|
| Command type | Processing query |
| Required permission | None |
| License usage | N/A |
| Parallel execution | Not supported |
| Distributed execution | Not supported |
Syntax
Options
degree=INT- Degree of the polynomial function to fit to the input data. Default:
3
Target
X_FIELD- Field to use as the independent variable. The field value must be numeric.
Y_FIELD- Field to use as the dependent variable. The field value must be numeric.
Output fields
| Field | Type | Description |
|---|---|---|
| _x | float | Value of the independent variable field |
| _p | float | Predicted value computed by the polynomial function |
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
| 40804 | Machine learning license is required. | Machine learning license is not present. |
| missing-curvefit-fields | - | Both the independent and dependent variable fields are not specified. |
Runtime errors
N/A
Description
The curvefit command performs least squares linear regression on up to 10,000 input records. The independent variable field value is output as the _x field, and the predicted value computed by the polynomial function is output as the _p field. Records beyond 10,000 are ignored.
Records where the independent or dependent variable value is not numeric are excluded from the analysis. Use the degree option to specify the polynomial degree. The default is a 3rd-degree polynomial.
A machine learning license is required to use this command.
Examples
-
Fitting data with a 3rd-degree polynomial
json "[{'x': 1, 'y': 2}, {'x': 2, 'y': 5}, {'x': 3, 'y': 10}, {'x': 4, 'y': 17}, {'x': 5, 'y': 26}]" | curvefit x, yFits a default 3rd-degree polynomial using the
xfield as the independent variable and theyfield as the dependent variable. -
Fitting CPU usage trends with a 10th-degree polynomial
table duration=1h sys_cpu_logs | eval x = datediff(dateadd(now(), "hour", -1), _time, "sec") | eval total = kernel + user | curvefit degree=10 x, totalFits the past hour's CPU usage trend with a 10th-degree polynomial. The predicted value is output in the
_pfield. -
Regression analysis with a specified degree
table duration=1d sensor_data | curvefit degree=5 seq, temperatureFits a 5th-degree polynomial using the
seqfield as the independent variable and thetemperaturefield as the dependent variable.