Ejemplo n.º 1
0
def test_combine_experiments_wrong_multiple():
    """Test the combination of experimental results for different
    datasets, oversamplers and classifiers and scoring."""

    # Clone and fit experiments
    experiment1 = (clone(EXPERIMENT).set_params(
        oversamplers=[('bsmote', BorderlineSMOTE(), {
            'k_neighbors': [2, 5]
        })],
        classifiers=[('gbc', GradientBoostingClassifier(), {})],
        scoring='f1',
    ).fit(DATASETS[:-1]))
    experiment2 = clone(EXPERIMENT).fit(DATASETS[-1:])
    with pytest.raises(ValueError):
        combine_results(experiment1.results_, experiment2.results_)
Ejemplo n.º 2
0
def test_combine_results_multiple():
    """Test the combination of experimental results for different
    datasets, oversamplers and classifiers."""

    # Clone and fit experiments
    experiment1 = (clone(EXPERIMENT).set_params(
        oversamplers=[('bsmote', BorderlineSMOTE(), {
            'k_neighbors': [2, 5]
        })],
        classifiers=[('gbc', GradientBoostingClassifier(), {})],
        scoring=['accuracy', 'f1'],
    ).fit(DATASETS[:-1]))
    experiment2 = (clone(EXPERIMENT).set_params(
        scoring=['accuracy', 'f1']).fit(DATASETS[-1:]))

    # Extract combined results
    combined_results = combine_results(experiment1.results_,
                                       experiment2.results_)
    results = combined_results.reset_index()

    # Assertions
    assert set(results.Dataset) == {'A', 'B', 'C'}
    assert set(results.Oversampler) == {'random', 'smote', 'bsmote'}
    assert set(results.Classifier) == {'dtc', 'knc', 'gbc'}
    assert set([scorer[0] for scorer in combined_results.columns
                ]) == set(['accuracy', 'f1'])
    pd.testing.assert_frame_equal(
        combined_results,
        pd.concat([experiment1.results_, experiment2.results_]).sort_index(),
    )
Ejemplo n.º 3
0
def test_combine_results_datasets():
    """Test the combination of experimental results for different datasets."""

    # Clone and fit experiments
    experiment1 = clone(EXPERIMENT).fit(DATASETS[:-1])
    experiment2 = clone(EXPERIMENT).fit(DATASETS[-1:])

    # Extract combined results
    combined_results = combine_results(experiment1.results_,
                                       experiment2.results_)
    results = combined_results.reset_index()

    # Assertions
    assert set(results.Dataset) == {'A', 'B', 'C'}
    assert set(results.Oversampler) == {'random', 'smote'}
    assert set(results.Classifier) == {'dtc', 'knc'}
    assert set([scorer[0]
                for scorer in combined_results.columns]) == set(['accuracy'])
    pd.testing.assert_frame_equal(
        combined_results,
        pd.concat([experiment1.results_, experiment2.results_]).sort_index(),
    )