foundryts.functions.polynomial_regression¶
foundryts.functions.polynomial_regression(max_degree=0, time_unit='ns', start=None, end=None)¶
Returns a function that computes the polynomial regression for a single time series.
Polynomial regression finds parameters of the best-fit polynomial curve of a specified degree over the points of
the input time series. The polynomial is expressed as y = a0 + a1*x + a2*x^2 + ... + an*x^n, where the
coefficients a0, a1, ..., an are determined by the regression.
Polynomial regression is useful when the relationship between the variables is more complex than a simple linear relationship.
- Parameters:
- max_degree (int , optional) – The maximum degree of the polynomial to fit (default is 0). For example, a degree of 2 fits a quadratic polynomial.
- time_unit (str , optional) – The time unit of the coefficients, must be one of “s”, “ms”, “us”, “ns” (default is “ns”).
- start (str | int | datetime.datetime , optional) – Starting point (inclusive) of the time series for computing the polynomial regression.
- end (str | int | datetime.datetime , optional) – End point (exclusive) of the time series for computing the polynomial regression.
- Returns: A function that accepts a single time series and returns parameters for the best-fit polynomial curve for the points in the time series using polynomial regression.
- Return type:
(
FunctionNode) ->SummarizerNode
Dataframe schema¶
| Column name | Type | Description |
|---|---|---|
| max_bounds.first_value | float | Maximum value of the first coefficient (a0). |
| max_bounds.second_value | float | Maximum value of the second coefficient (a1). |
| min_bounds.first_value | float | Minimum value of the first coefficient (a0). |
| min_bounds.second_value | float | Minimum value of the second coefficient (a1). |
| regression_fit_function. polynomial_regression_fit. coefficients.coefficient |
float | Coefficient value of the polynomial regression fit. |
| regression_fit_function. polynomial_regression_fit. coefficients.degree |
int | Degree of the polynomial corresponding to each coefficient. |
:::callout{theme="success" title="See Also"}
exponential_regression(), linear_regression()
:::
:::callout{theme="warning" title="Note"} This function is only applicable to numeric series. :::
Examples¶
>>> series = F.points(
... (10, 6.0), (20, 12.0), (30, 24.0), (40, 48.0), (50, 96.0), name="series"
... )
>>> series.to_pandas()
timestamp value
0 1970-01-01 00:00:00.000000010 6.0
1 1970-01-01 00:00:00.000000020 12.0
2 1970-01-01 00:00:00.000000030 24.0
3 1970-01-01 00:00:00.000000040 48.0
4 1970-01-01 00:00:00.000000050 96.0
>>> poly_regr = F.polynomial_regression(3)(series)
>>> poly_regr.to_pandas()
max_bounds.first_value max_bounds.second_value min_bounds.first_value min_bounds.second_value regression_fit_function.polynomial_regression_fit.coefficients.coefficient regression_fit_function.polynomial_regression_fit.coefficients.degree
0 50.0 96.0 10.0 6.0 -4.800000 0
1 50.0 96.0 10.0 6.0 1.585714 1
2 50.0 96.0 10.0 6.0 -0.066429 2
3 50.0 96.0 10.0 6.0 0.001500 3
中文翻译¶
foundryts.functions.polynomial_regression¶
foundryts.functions.polynomial_regression(max_degree=0, time_unit='ns', start=None, end=None)¶
返回一个函数,用于计算单个时间序列的多项式回归(Polynomial Regression)。
多项式回归在输入时间序列的数据点上,找到指定阶数的最佳拟合多项式曲线的参数。多项式表示为 y = a0 + a1*x + a2*x^2 + ... + an*x^n,其中系数 a0, a1, ..., an 由回归计算确定。
当变量之间的关系比简单的线性关系更复杂时,多项式回归非常有用。
- 参数(Parameters):
- max_degree (int , 可选) – 要拟合的多项式的最大阶数(默认为 0)。例如,阶数为 2 时拟合二次多项式。
- time_unit (str , 可选) – 系数的时间单位,必须为 "s"、"ms"、"us"、"ns" 之一(默认为 "ns")。
- start (str | int | datetime.datetime , 可选) – 用于计算多项式回归的时间序列的起始点(包含)。
- end (str | int | datetime.datetime , 可选) – 用于计算多项式回归的时间序列的结束点(不包含)。
- 返回(Returns): 一个函数,接受单个时间序列,并使用多项式回归返回该时间序列中数据点的最佳拟合多项式曲线的参数。
- 返回类型(Return type):
(
FunctionNode) ->SummarizerNode
数据框模式(Dataframe schema)¶
| 列名 | 类型 | 描述 |
|---|---|---|
| max_bounds.first_value | float | 第一个系数 (a0) 的最大值。 |
| max_bounds.second_value | float | 第二个系数 (a1) 的最大值。 |
| min_bounds.first_value | float | 第一个系数 (a0) 的最小值。 |
| min_bounds.second_value | float | 第二个系数 (a1) 的最小值。 |
| regression_fit_function. polynomial_regression_fit. coefficients.coefficient |
float | 多项式回归拟合的系数值。 |
| regression_fit_function. polynomial_regression_fit. coefficients.degree |
int | 每个系数对应的多项式阶数。 |
:::callout{theme="success" title="另请参阅(See Also)"}
exponential_regression(), linear_regression()
:::
:::callout{theme="warning" title="注意(Note)"} 此函数仅适用于数值型序列。 :::
示例(Examples)¶
>>> series = F.points(
... (10, 6.0), (20, 12.0), (30, 24.0), (40, 48.0), (50, 96.0), name="series"
... )
>>> series.to_pandas()
timestamp value
0 1970-01-01 00:00:00.000000010 6.0
1 1970-01-01 00:00:00.000000020 12.0
2 1970-01-01 00:00:00.000000030 24.0
3 1970-01-01 00:00:00.000000040 48.0
4 1970-01-01 00:00:00.000000050 96.0
>>> poly_regr = F.polynomial_regression(3)(series)
>>> poly_regr.to_pandas()
max_bounds.first_value max_bounds.second_value min_bounds.first_value min_bounds.second_value regression_fit_function.polynomial_regression_fit.coefficients.coefficient regression_fit_function.polynomial_regression_fit.coefficients.degree
0 50.0 96.0 10.0 6.0 -4.800000 0
1 50.0 96.0 10.0 6.0 1.585714 1
2 50.0 96.0 10.0 6.0 -0.066429 2
3 50.0 96.0 10.0 6.0 0.001500 3