Example #1
0
def test_cutoff_window_splitter(y, cutoffs, fh, window_length):
    """Test CutoffSplitter."""
    if _inputs_are_supported([cutoffs, fh, window_length]):
        cv = CutoffSplitter(cutoffs, fh=fh, window_length=window_length)
        train_windows, test_windows, cutoffs, n_splits = _check_cv(cv, y)
        np.testing.assert_array_equal(cutoffs, cv.get_cutoffs(y))
    else:
        match = "Unsupported combination of types"
        with pytest.raises(TypeError, match=match):
            CutoffSplitter(cutoffs, fh=fh, window_length=window_length)
def test_cutoff_window_splitter(y, cutoffs, fh, window_length):
    """Test CutoffSplitter."""
    cv = CutoffSplitter(cutoffs, fh=fh, window_length=window_length)
    if _cutoffs_fh_window_length_types_are_supported(
            cutoffs=cutoffs,
            fh=ForecastingHorizon(fh),
            window_length=window_length):
        train_windows, test_windows, cutoffs, n_splits = _check_cv(cv, y)
        np.testing.assert_array_equal(cutoffs, cv.get_cutoffs(y))
    else:
        match = "Unsupported combination of types"
        with pytest.raises(TypeError, match=match):
            _check_cv(cv, y)
Example #3
0
    def _predict_in_sample(self,
                           fh,
                           X=None,
                           return_pred_int=False,
                           alpha=DEFAULT_ALPHA):
        """Make in-sample prediction using single-step moving-cutoff
        predictions

        Parameters
        ----------
        fh : np.array
            all non-positive (<= 0)
        X : pd.DataFrame
        return_pred_int : bool
        alpha : float or array-like

        Returns
        -------
        y_pred : pd.DataFrame or pd.Series
        """
        y_train = self._y

        # generate cutoffs from forecasting horizon, note that cutoffs are
        # still based on integer indexes,
        # so that they can be used with .iloc
        cutoffs = fh + len(y_train) - 2
        cv = CutoffSplitter(cutoffs, fh=1, window_length=self.window_length_)
        return self._predict_moving_cutoff(y_train,
                                           cv,
                                           X=X,
                                           update_params=False,
                                           return_pred_int=return_pred_int,
                                           alpha=alpha)
Example #4
0
def test_manual_window_split(y, cutoffs, fh, window_length):
    # initiate rolling window cv iterator
    cv = CutoffSplitter(cutoffs, fh=fh, window_length=window_length)

    # generate and keep splits
    training_windows, test_windows, n_splits, _ = generate_and_check_windows(
        y, cv)

    # check cutoffs
    np.testing.assert_array_equal(cutoffs, cv.get_cutoffs(y))

    # check training windows
    n_incomplete_windows = get_n_incomplete_windows(training_windows,
                                                    window_length)
    check_windows_dimensions(training_windows, n_incomplete_windows,
                             window_length)

    # check test windows
    check_test_windows(test_windows, fh, cutoffs)
Example #5
0
def test_cutoff_window_splitter(y, cutoffs, fh, window_length):
    """Test CutoffSplitter."""
    cv = CutoffSplitter(cutoffs, fh=fh, window_length=window_length)
    train_windows, test_windows, cutoffs, n_splits = _check_cv(cv, y)
    np.testing.assert_array_equal(cutoffs, cv.get_cutoffs(y))