def test_sample_selection_working(): pool_classifiers = create_pool_all_agree(0, 10) + create_pool_all_agree( 1, 5) meta_test = METADES(pool_classifiers=pool_classifiers) meta_test.n_classifiers_ = len(pool_classifiers) meta_test.DSEL_processed_ = np.ones((5, 15)) meta_test.DSEL_processed_[(1, 3, 4), 5:] = 0 expected = np.asarray([1, 1 / 3, 1, 1 / 3, 1 / 3]) value = meta_test._sample_selection_agreement() assert np.array_equal(value, expected)
def test_compute_meta_features(example_estimate_competence, create_pool_classifiers): X, y, nn, _, dsel_processed, dsel_scores = example_estimate_competence query = np.ones((1, 2)) pool = create_pool_classifiers meta_test = METADES(pool_classifiers=[pool[0]]) meta_test.n_classifiers_ = 1 meta_test.k_ = 7 meta_test.Kp_ = 5 # Considering only one classifier in the pool (index = 0) meta_test.DSEL_processed_ = dsel_processed[:, 0].reshape(-1, 1) meta_test.dsel_scores_ = dsel_scores[:, 0, :].reshape(15, 1, 2) meta_test.DSEL_target_ = y meta_test.n_classes_ = 2 neighbors_op = nn[2, 0:meta_test.Kp] # Expected values for each meta feature based on the data of ex1. expected_f1 = [1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0] expected_f2 = [1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0] expected_f3 = [4.0 / 7.0] expected_f4 = [0.0, 1.0, 1.0, 1.0, 0.0] expected_f5 = [0.5] scores = np.empty( (query.shape[0], meta_test.n_classifiers_, meta_test.n_classes_)) for index, clf in enumerate(meta_test.pool_classifiers): scores[:, index, :] = clf.predict_proba(query) meta_features = meta_test.compute_meta_features(scores, nn[0, :], neighbors_op) expected = np.asarray(expected_f1 + expected_f2 + expected_f3 + expected_f4 + expected_f5) assert np.array_equal(meta_features, expected.reshape(1, -1))
def test_select_no_competent_classifiers_batch(): meta_test = METADES() meta_test.n_classifiers_ = 3 competences = np.zeros((10, meta_test.n_classifiers_)) selected_matrix = meta_test.select(competences) assert np.all(selected_matrix)