

def seasonal_decompose(x, model='additive', filt=None, freq=None):
    '\n    Parameters\n    ----------\n    x : array-like\n        Time series\n    model : str {"additive", "multiplicative"}\n        Type of seasonal component. Abbreviations are accepted.\n    filt : array-like\n        The filter coefficients for filtering out the seasonal component.\n        The default is a symmetric moving average.\n    freq : int, optional\n        Frequency of the series. Must be used if x is not a pandas\n        object with a timeseries index.\n\n    Returns\n    -------\n    results : obj\n        A object with seasonal, trend, and resid attributes.\n\n    Notes\n    -----\n    This is a naive decomposition. More sophisticated methods should\n    be preferred.\n\n    The additive model is Y[t] = T[t] + S[t] + e[t]\n\n    The multiplicative model is Y[t] = T[t] * S[t] * e[t]\n\n    The seasonal component is first removed by applying a convolution\n    filter to the data. The average of this smoothed series for each\n    period is the returned seasonal component.\n\n    See Also\n    --------\n    statsmodels.tsa.filters.convolution_filter\n    '
    (_pandas_wrapper, pfreq) = _maybe_get_pandas_wrapper_freq(x)
    x = np.asanyarray(x).squeeze()
    nobs = len(x)
    if (not np.all(np.isfinite(x))):
        raise ValueError('This function does not handle missing values')
    if model.startswith('m'):
        if np.any((x <= 0)):
            raise ValueError('Multiplicative seasonality is not appropriate for zero and negative values')
    if (pfreq is not None):
        pfreq = freq_to_period(pfreq)
        if (freq and (pfreq != freq)):
            raise ValueError("Inferred frequency of index and frequency don't match. This function does not re-sample")
        else:
            freq = pfreq
    elif (freq is None):
        raise ValueError('You must specify a freq or x must be a pandas object with a timeseries index')
    if (filt is None):
        if ((freq % 2) == 0):
            filt = (np.array((([0.5] + ([1] * (freq - 1))) + [0.5])) / freq)
        else:
            filt = np.repeat((1.0 / freq), freq)
    trend = convolution_filter(x, filt)
    if model.startswith('m'):
        detrended = (x / trend)
    else:
        detrended = (x - trend)
    period_averages = seasonal_mean(detrended, freq)
    if model.startswith('m'):
        period_averages /= np.mean(period_averages)
    else:
        period_averages -= np.mean(period_averages)
    seasonal = np.tile(period_averages, ((nobs // freq) + 1))[:nobs]
    if model.startswith('m'):
        resid = ((x / seasonal) / trend)
    else:
        resid = (detrended - seasonal)
    results = lmap(_pandas_wrapper, [seasonal, trend, resid, x])
    return DecomposeResult(seasonal=results[0], trend=results[1], resid=results[2], observed=results[3])

dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/tsa/seasonal.py seasonal_decompose/original