def test_estimate_competence_batch(example_estimate_competence): _, _, neighbors, distances, dsel_processed, _ = example_estimate_competence expected = np.array([[1, 5, 0], [1, 1, 2], [0, 0, 1]]) rank_test = Rank() rank_test.DSEL_processed_ = dsel_processed competences = rank_test.estimate_competence(neighbors, distances=distances) assert np.allclose(competences, expected)
def test_estimate_competence(index, expected): rank_test = Rank(create_pool_classifiers()) rank_test.processed_dsel = dsel_processed_ex1 rank_test.neighbors = neighbors_ex1[index, :] rank_test.distances = distances_ex1[index, :] rank_test.DFP_mask = [1, 1, 1] query = np.array([1, 1]) competences = rank_test.estimate_competence(query.reshape(1, -1)) assert np.isclose(competences, expected).all()
def test_estimate_competence_batch(): expected = np.array([[1, 5, 0], [1, 1, 2], [0, 0, 1]]) rank_test = Rank(create_pool_classifiers()) rank_test.processed_dsel = dsel_processed_ex1 rank_test.neighbors = neighbors_ex1 rank_test.distances = distances_ex1 rank_test.DFP_mask = np.ones((3, 3)) query = np.array([[1, 1], [1, 1], [1, 1]]) competences = rank_test.estimate_competence(query) assert np.allclose(competences, expected)
def test_estimate_competence_batch(): expected = np.array([[1, 5, 0], [1, 1, 2], [0, 0, 1]]) rank_test = Rank(create_pool_classifiers()) rank_test.DSEL_processed_ = dsel_processed_ex1 neighbors = neighbors_ex1 distances = distances_ex1 query = np.array([[1, 1], [1, 1], [1, 1]]) competences = rank_test.estimate_competence(query, neighbors, distances=distances) assert np.allclose(competences, expected)
def test_rank(): pool_classifiers, X_dsel, y_dsel, X_test, y_test = setup_classifiers() rank = Rank(pool_classifiers, DFP=True) rank.fit(X_dsel, y_dsel) assert np.isclose(rank.score(X_test, y_test), 0.8787878787878788)
def test_rank(knn_methods): pool_classifiers, X_dsel, y_dsel, X_test, y_test = setup_classifiers() rank = Rank(pool_classifiers, knn_classifier=knn_methods) rank.fit(X_dsel, y_dsel) assert np.isclose(rank.score(X_test, y_test), 0.973404255319149)
def test_predict_proba(): X = X_dsel_ex1 y = y_dsel_ex1 clf1 = Perceptron() clf1.fit(X, y) Rank([clf1, clf1]).fit(X, y)
plt.show() plt.tight_layout() ############################################################################### # Comparison with Dynamic Selection techniques # -------------------------------------------- # # We will now consider four DS methods: k-Nearest Oracle-Eliminate (KNORA-E), # Dynamic Ensemble Selection performance (DES-P), Overall Local Accuracy (OLA) # and Rank. Let's train the classifiers and plot their decision boundaries: knora_e = KNORAE(pool_classifiers).fit(X_train, y_train) desp = DESP(pool_classifiers).fit(X_train, y_train) ola = OLA(pool_classifiers).fit(X_train, y_train) rank = Rank(pool_classifiers).fit(X_train, y_train) # Plotting the Decision Border of the DS methods. fig2, sub = plt.subplots(2, 2, figsize=(15, 10)) plt.subplots_adjust(wspace=0.4, hspace=0.4) titles = [ 'KNORA-Eliminate', 'DES-P', 'Overall Local Accuracy (OLA)', 'Modified Rank' ] classifiers = [knora_e, desp, ola, rank] for clf, ax, title in zip(classifiers, sub.flatten(), titles): plot_classifier_decision(ax, clf, X_train, mode='filled', alpha=0.4) plot_dataset(X_test, y_test, ax=ax) ax.set_xlim(np.min(X[:, 0]), np.max(X[:, 0])) ax.set_ylim(np.min(X[:, 1]), np.max(X[:, 1])) ax.set_title(title, fontsize=15)
def test_check_estimator(): check_estimator(Rank())
def test_predict_proba(create_X_y): X, y = create_X_y clf1 = Perceptron() clf1.fit(X, y) Rank([clf1, clf1]).fit(X, y)
def test_rank(): pool_classifiers, X_dsel, y_dsel, X_test, y_test = setup_classifiers() rank = Rank(pool_classifiers) rank.fit(X_dsel, y_dsel) assert np.isclose(rank.score(X_test, y_test), 0.96276595744680848)