gramex.sm_api

StatsModel(mclass, params, kwargs)

Source code in gramex\sm_api.py
18
19
20
21
22
23
24
def __init__(self, mclass, params, **kwargs):
    self.stl_kwargs = kwargs.pop("stl", False)
    if isinstance(mclass, SARIMAXResultsWrapper):
        self.res = mclass
    self.mclass = mclass
    self.params = params
    self.kwargs = kwargs

fit(X, y=None, model_path=None, name=None, index_col=None, target_col=None, kwargs)

Only a dataframe is accepted. Index and target columns are both expected to be in it.

Source code in gramex\sm_api.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def fit(
    self, X, y=None, model_path=None, name=None, index_col=None, target_col=None, **kwargs
):
    """Only a dataframe is accepted. Index and target columns are both expected to be in it."""
    params = self.params.copy()
    X = self._timestamp_data(X, index_col)
    if y is None:
        y = X[target_col]
        X = X.drop([target_col], axis=1)
    else:
        y.index = X.index
    endog = y
    exog = X.drop([target_col], axis=1) if target_col in X else X
    params["exog"] = exog
    endog.index.freq = self.params.pop("freq", pd.infer_freq(endog.index))
    endog = self._get_stl(endog)
    exog.index = endog.index
    missing = self.params.pop("missing", "drop")
    self.model = self.mclass(endog, missing=missing, **params)
    self.res = self.model.fit()
    self.res.save(model_path)
    return self.res.summary().as_html()