MCPcopy Create free account
hub / github.com/modAL-python/modAL / test_on_transformed

Method test_on_transformed

tests/core_tests.py:1493–1529  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1491 committee.teach(X, y, bootstrap=bootstrap, only_new=only_new)
1492
1493 def test_on_transformed(self):
1494 n_samples = 10
1495 n_features = 5
1496 query_strategies = [
1497 modAL.batch.uncertainty_batch_sampling
1498 # add further strategies which work with instance representations
1499 # no further ones as of 25.09.2020
1500 ]
1501 X_pool = np.random.rand(n_samples, n_features)
1502
1503 # use pandas data frame as X_pool, which will be transformed back to numpy with sklearn pipeline
1504 X_pool = pd.DataFrame(X_pool)
1505
1506 y_pool = np.random.randint(0, 2, size=(n_samples,))
1507 train_idx = np.random.choice(range(n_samples), size=5, replace=False)
1508
1509 learner_list = [modAL.models.learners.ActiveLearner(
1510 estimator=make_pipeline(
1511 FunctionTransformer(func=pd.DataFrame.to_numpy),
1512 RandomForestClassifier(n_estimators=10)
1513 ),
1514 # committee learners can contain different amounts of
1515 # different instances
1516 X_training=X_pool.iloc[train_idx[(
1517 np.arange(i + 1) + i) % len(train_idx)]],
1518 y_training=y_pool[train_idx[(
1519 np.arange(i + 1) + i) % len(train_idx)]],
1520 ) for i in range(3)]
1521
1522 for query_strategy in query_strategies:
1523 committee = modAL.models.learners.Committee(
1524 learner_list=learner_list,
1525 query_strategy=query_strategy,
1526 on_transformed=True
1527 )
1528 query_idx, query_inst = committee.query(X_pool)
1529 committee.teach(X_pool.iloc[query_idx], y_pool[query_idx])
1530
1531
1532class TestCommitteeRegressor(unittest.TestCase):

Callers

nothing calls this directly

Calls 2

teachMethod · 0.95
queryMethod · 0.45

Tested by

no test coverage detected