def fit(self, X, y, method='smoother', delta=None, include_constant=None):
        """
        Fit the coefficients for the dynamic linear model.

        @param method: The method used to estimate the dynamic coefficients, either 'smoother' or 'filter'. If
            'smoother', then the Kalman Smoother is used, otherwise the Kalman Filter will be used. The two differ
             in the fact that the Kalman Smoother uses both future and past data, while the Kalman Filter only uses
             past data.
        @param X: The time-varying covariates, and (ntime, pfeat) array.
        @param y: The time-varying response, a 1-D array with ntime elements.
        @param delta: The regularization parameters on the time variation of the coefficients. Default is
            self.delta.
        @param include_constant: Boolean, if true then include a constant in the regression model.
        """
        try:
            method.lower() in ['smoother', 'filter']
        except __HOLE__:
            "method must be either 'smoother' or 'filter'."

        if delta is None:
            delta = self.delta
        else:
            self.delta = delta

        if include_constant is None:
            include_constant = self.include_constant
        else:
            self.include_constant = include_constant

        if include_constant:
            Xtemp = self.add_constant_(X.copy())
        else:
            Xtemp = X.copy()

        ntime, pfeat = Xtemp.shape

        observation_matrix = Xtemp.reshape((ntime, 1, pfeat))
        observation_offset = np.array([0.0])

        transition_matrix = np.identity(pfeat)
        transition_offset = np.zeros(pfeat)

        mu = (1.0 - delta) / delta
        # Var(beta_t - beta_{t-1}) = 1.0 / mu
        transition_covariance = np.identity(pfeat) / mu

        # parameters to be estimated using MLE
        em_vars = ['initial_state_mean', 'initial_state_covariance']
        kalman = pykalman.KalmanFilter(transition_matrices=transition_matrix, em_vars=em_vars,
                                       observation_matrices=observation_matrix,
                                       observation_offsets=observation_offset, transition_offsets=transition_offset,
                                       observation_covariance=np.array([1.0]),
                                       transition_covariance=transition_covariance)

        kalman.em(y)
        if method is 'smoother':
            beta, beta_covar = kalman.smooth(y)
        else:
            beta, beta_covar = kalman.filter(y)

        self.beta = beta
        self.beta_cov = beta_covar
        self.current_beta = beta[-1]
        self.current_bcov = beta_covar[-1]
        self.kalman = kalman
dataset/ETHPy150Open brandonckelly/bck_stats/bck_stats/dynamic_linear_model.py/DynamicLinearModel.fit