Ejemplo n.º 1
0
def test_tde_on_gunpoint():
    # load gunpoint data
    X_train, y_train = load_gunpoint(split='train', return_X_y=True)
    X_test, y_test = load_gunpoint(split='test', return_X_y=True)
    indices = np.random.RandomState(0).permutation(10)

    # train tde
    tde = TemporalDictionaryEnsemble(random_state=0)
    tde.fit(X_train.iloc[indices], y_train[indices])

    # assert probabilities are the same
    probas = tde.predict_proba(X_test.iloc[indices])
    testing.assert_array_equal(probas, tde_gunpoint_probas)
Ejemplo n.º 2
0
def test_contracted_tde_on_unit_test_data():
    """Test of contracted TDE on unit test data."""
    # load unit test data
    X_train, y_train = load_unit_test(split="train")

    # train contracted TDE
    tde = TemporalDictionaryEnsemble(
        time_limit_in_minutes=0.25,
        contract_max_n_parameter_samples=10,
        max_ensemble_size=5,
        randomly_selected_params=5,
        random_state=0,
    )
    tde.fit(X_train, y_train)

    assert len(tde.estimators_) > 1
Ejemplo n.º 3
0
def test_contracted_tde_on_unit_test_data():
    """Test of contracted TDE on unit test data."""
    # load unit test data
    X_train, y_train = load_unit_test(split="train", return_X_y=True)
    X_test, y_test = load_unit_test(split="test", return_X_y=True)

    # train contracted TDE
    tde = TemporalDictionaryEnsemble(
        time_limit_in_minutes=0.025,
        max_ensemble_size=5,
        randomly_selected_params=5,
        random_state=0,
    )
    tde.fit(X_train, y_train)

    assert len(tde.estimators_) > 1
    assert accuracy_score(y_test, tde.predict(X_test)) >= 0.8
Ejemplo n.º 4
0
def test_tde_on_power_demand():
    # load power demand data
    X_train, y_train = load_italy_power_demand(split="train", return_X_y=True)
    X_test, y_test = load_italy_power_demand(split="test", return_X_y=True)
    indices = np.random.RandomState(0).permutation(100)

    # train TDE
    tde = TemporalDictionaryEnsemble(
        n_parameter_samples=50,
        max_ensemble_size=10,
        randomly_selected_params=40,
        random_state=0,
    )
    tde.fit(X_train, y_train)

    score = tde.score(X_test.iloc[indices], y_test[indices])
    assert score >= 0.92
Ejemplo n.º 5
0
def test_tde_on_unit_test_data():
    """Test of TDE on unit test data."""
    # load unit test data
    X_train, y_train = load_unit_test(split="train", return_X_y=True)
    X_test, y_test = load_unit_test(split="test", return_X_y=True)
    indices = np.random.RandomState(0).choice(len(y_train), 10, replace=False)

    # train TDE
    tde = TemporalDictionaryEnsemble(
        n_parameter_samples=10,
        max_ensemble_size=5,
        randomly_selected_params=5,
        random_state=0,
    )
    tde.fit(X_train, y_train)

    # assert probabilities are the same
    probas = tde.predict_proba(X_test.iloc[indices]).round(6)
    testing.assert_array_equal(probas, tde_unit_test_probas)

    # test loocv train estimate
    train_probas = tde._get_train_probs(X_train, y_train)
    train_preds = tde.classes_[np.argmax(train_probas, axis=1)]
    assert accuracy_score(y_train, train_preds) >= 0.85

    # test oob estimate
    train_probas = tde._get_train_probs(X_train,
                                        y_train,
                                        train_estimate_method="oob")
    train_preds = tde.classes_[np.argmax(train_probas, axis=1)]
    assert accuracy_score(y_train, train_preds) >= 0.8
Ejemplo n.º 6
0
def test_tde_on_basic_motions():
    # load basic motions data
    X_train, y_train = load_basic_motions(split="train", return_X_y=True)
    X_test, y_test = load_basic_motions(split="test", return_X_y=True)
    indices = np.random.RandomState(0).permutation(20)

    # train TDE
    tde = TemporalDictionaryEnsemble(
        n_parameter_samples=50,
        max_ensemble_size=10,
        randomly_selected_params=40,
        random_state=0,
    )
    tde.fit(X_train.iloc[indices], y_train[indices])

    # assert probabilities are the same
    probas = tde.predict_proba(X_test.iloc[indices])
    testing.assert_array_equal(probas, tde_basic_motions_probas)
Ejemplo n.º 7
0
def test_tde_on_basic_motions():
    """Test of TDE on basic motions data."""
    # load basic motions data
    X_train, y_train = load_basic_motions(split="train", return_X_y=True)
    X_test, y_test = load_basic_motions(split="test", return_X_y=True)
    indices = np.random.RandomState(4).choice(len(y_train), 10, replace=False)

    # train TDE
    tde = TemporalDictionaryEnsemble(
        n_parameter_samples=10,
        max_ensemble_size=5,
        randomly_selected_params=5,
        random_state=0,
    )
    tde.fit(X_train.iloc[indices], y_train[indices])

    # assert probabilities are the same
    probas = tde.predict_proba(X_test.iloc[indices]).round(6)
    testing.assert_array_equal(probas, tde_basic_motions_probas)
Ejemplo n.º 8
0
def test_tde_train_estimate():
    """Test of TDE train estimate on unit test data."""
    # load unit test data
    X_train, y_train = load_unit_test(split="train")

    # train TDE
    tde = TemporalDictionaryEnsemble(
        n_parameter_samples=5,
        max_ensemble_size=2,
        randomly_selected_params=3,
        random_state=0,
        save_train_predictions=True,
    )
    tde.fit(X_train, y_train)

    # test loocv train estimate
    train_probas = tde._get_train_probs(X_train, y_train)
    assert train_probas.shape == (20, 2)
    train_preds = tde.classes_[np.argmax(train_probas, axis=1)]
    assert accuracy_score(y_train, train_preds) >= 0.6

    # test oob estimate
    train_probas = tde._get_train_probs(X_train,
                                        y_train,
                                        train_estimate_method="oob")
    assert train_probas.shape == (20, 2)
    train_preds = tde.classes_[np.argmax(train_probas, axis=1)]
    assert accuracy_score(y_train, train_preds) >= 0.6