def test_lstm_tsp_forecast_oze(user_name, user_password):
    """
    Tests the LSTMTimeSeriesPredictor
    """
    tsp = TimeSeriesPredictor(
        BenchmarkLSTM(hidden_dim=64),
        max_epochs=5,
        # train_split=None, # default = skorch.dataset.CVSplit(5)
        optimizer=torch.optim.Adam)
    dataset = _get_dataset(user_name, user_password)

    tsp.fit(dataset)
    mean_r2_score = tsp.score(tsp.dataset)
    assert mean_r2_score > -300

    predictions = tsp.forecast(500)
    assert len(predictions) == len(dataset) + 500
示例#2
0
def test_quantum_lstm_tsp_forecast(device):
    """
    Tests the Quantum LSTM forecast
    """
    cuda_check(device)

    tsp = TimeSeriesPredictor(
        QuantumLSTM(hidden_dim = 2),
        max_epochs=250,
        lr = 1e-4,
        early_stopping=EarlyStopping(patience=100, monitor='train_loss'),
        train_split=None,
        optimizer=Adam,
        device=device
    )

    whole_fd = FlightsDataset()
    # leave last N months for error assertion
    last_n = 24
    start = time.time()
    tsp.fit(FlightsDataset(pattern_length = 120, except_last_n = last_n))
    end = time.time()
    elapsed = timedelta(seconds = end - start)
    print(f"Fitting in {device} time delta: {elapsed}")
    mean_r2_score = tsp.score(tsp.dataset)
    assert mean_r2_score > -5

    netout, _ = tsp.forecast(last_n)

    # Select any training example just for comparison
    idx = np.random.randint(0, len(tsp.dataset))
    _, whole_y = whole_fd[idx]

    y_true = whole_y[-last_n:, :]   # get only known future outputs
    y_pred = netout[idx, -last_n:, :]    # get only last N predicted outputs
    r2s = r2_score(y_true, y_pred)
    assert r2s > -60