linear_regression: 선형 추세 적합
foundryts.functions.linear_regression(
include_intercept=True, time_unit='ns', start=None, end=None
)
숫자형 시계열 하나의 관측에 y = A * x + B 형태의 직선을 적합하는 함수를 반환합니다. A는 기울기이고 B는 y절편입니다. 입력은 FunctionNode, 결과는 SummarizerNode입니다.
인수
| 인수 | 형식 | 기본값과 의미 |
|---|---|---|
| include_intercept | bool | True. 절편 포함 여부 |
| time_unit | str | ns. 계수의 시간 단위이며 s, ms, us, ns 중 선택 |
| start | str, int 또는 datetime.datetime | None. 시작 시각 포함 |
| end | str, int 또는 datetime.datetime | None. 종료 시각 제외 |
숫자형 시계열의 선형 경향을 정량화할 때 사용하며 범주형에는 적용하지 않습니다.
결과 필드
| 열 | 형식 | 의미 |
|---|---|---|
| min_bounds.first_value | float | 회귀 대상 x좌표의 최솟값 |
| max_bounds.first_value | float | 회귀 대상 x좌표의 최댓값 |
| min_bounds.second_value | float | 회귀 대상 y값의 최솟값 |
| max_bounds.second_value | float | 회귀 대상 y값의 최댓값 |
| regression_fit_function.linear_regression_fit.slope | float | 기울기 A |
| regression_fit_function.linear_regression_fit.intercept | float | 절편 B |
| regression_fit_function.linear_regression_fit.statistics.rsquared | float | 적합도를 나타내는 R² |
bounds는 데이터 좌표 범위입니다. 기울기나 절편의 범위 또는 신뢰구간으로 해석하지 않습니다.
가상 관측 예제
import foundryts.functions as F
series = F.points(
(10, 6.0),
(20, 12.0),
(30, 24.0),
(40, 48.0),
(50, 96.0),
name="series",
)
regression = F.linear_regression()(series)
regression_df = regression.to_pandas()
시각은 나노초이며 가상 결과의 필드는 다음과 같습니다.
| 필드 | 값 |
|---|---|
| min_bounds.first_value | 10.0 |
| max_bounds.first_value | 50.0 |
| min_bounds.second_value | 6.0 |
| max_bounds.second_value | 96.0 |
| regression_fit_function.linear_regression_fit.slope | 2.16 |
| regression_fit_function.linear_regression_fit.intercept | -27.6 |
| regression_fit_function.linear_regression_fit.statistics.rsquared | 약 0.870968 |
두 시계열의 값 사이에 직선을 적합하려면 scatter에 회귀 명세를 전달합니다. 다른 곡선은 exponential_regression과 polynomial_regression을 사용할 수 있습니다.