def test_estimate_competence(index, expected): query = np.array([1, 1]) mcb_test = MCB(create_pool_classifiers()) mcb_test.processed_dsel = dsel_processed_ex1 mcb_test.neighbors = neighbors_ex1[index, :] mcb_test.distances = distances_ex1[index, :] mcb_test.DFP_mask = [1, 1, 1] mcb_test.BKS_dsel = bks_dsel_ex1 competences = mcb_test.estimate_competence(query.reshape(1, -1)) assert np.isclose(competences, expected).all()
def test_estimate_competence3(index, expected): query = np.array([1, 1]) mcb_test = MCB(create_pool_classifiers()) mcb_test.processed_dsel = dsel_processed_ex1 mcb_test.neighbors = neighbors_ex1[index, :] mcb_test.distances = distances_ex1[index, :] mcb_test.DFP_mask = [1, 1, 1] # Only changing the pre-processed BKS to see if the filter works. mcb_test.BKS_dsel = bks_dsel_ex3 competences = mcb_test.estimate_competence(query.reshape(1, -1)) assert np.isclose(competences, expected).all()
def test_estimate_competence(index, expected): query = np.atleast_2d([1, 1]) mcb_test = MCB(create_pool_classifiers()) mcb_test.processed_dsel = dsel_processed_ex1 mcb_test.neighbors = neighbors_ex1[index, :] mcb_test.distances = distances_ex1[index, :] mcb_test.DFP_mask = [1, 1, 1] mcb_test.BKS_dsel = bks_dsel_ex1 predictions = [] for clf in mcb_test.pool_classifiers: predictions.append(clf.predict(query)[0]) competences = mcb_test.estimate_competence(query, predictions=np.atleast_2d(predictions)) assert np.isclose(competences, expected).all()
def test_estimate_competence_batch(): query = np.ones((3, 2)) expected = np.array([[0.57142857, 0.71428571, 0.71428571], [0.71428571, 0.85714286, 0.71428571], [0.57142857, 0.71428571, 0.57142857]]) mcb_test = MCB(create_pool_classifiers()) mcb_test.processed_dsel = dsel_processed_ex1 mcb_test.neighbors = neighbors_ex1 mcb_test.distances = distances_ex1 mcb_test.DFP_mask = np.ones((3, 3)) # Only changing the pre-processed BKS to see if the filter works. mcb_test.BKS_dsel = bks_dsel_ex3 predictions = [] for clf in mcb_test.pool_classifiers: predictions.append(clf.predict(query)[0]) competences = mcb_test.estimate_competence(query, predictions=np.tile(predictions, (3, 1))) assert np.isclose(competences, expected).all()