Linear Model
Using simple linear regression to explore relationship between observed value and time. For prediction intervals, we use weighted standard deviation method to get standard error and get prediction interval band.
API
# Parameter class
class LinearModelParams(alpha=0.05**`)`**
Parameters
alpha: `confidence level for two-sided hypothesis`
# Model class
class LinearModel()
Methods
fit(): # fit linear model with given parameters
predict(steps, freq): # predict the future for future steps
plot(): # plot forecaset reslut
Example
We use air passenger data as an example.
import pandas as pd
from infrastrategy.kats.consts import TimeSeriesData
from infrastrategy.kats.models.linearModel import LinearModelParams, LinearModel
# read and format data
file_path = "../data/air_passengers.csv"
data = pd.read_csv(file_path)
data.rename(columns={'ds': "time"}, inplace=True)
TSdata = TimeSeriesData(data)
# create parameters
params = LinearModelParams()
# creat model
m = LinearModel(params=params, data=TSdata)
m.fit()
fcst = m.predict(steps=60, freq="MS")
# plot forecast result
m.plot()