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

Class TestActiveLearner

tests/core_tests.py:926–1223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

924
925
926class TestActiveLearner(unittest.TestCase):
927
928 def test_add_training_data(self):
929 for n_samples in range(1, 10):
930 for n_features in range(1, 10):
931 for n_new_samples in range(1, 10):
932 # testing for valid cases
933 # 1. integer class labels
934 X_initial = np.random.rand(n_samples, n_features)
935 y_initial = np.random.randint(0, 2, size=(n_samples,))
936 X_new = np.random.rand(n_new_samples, n_features)
937 y_new = np.random.randint(0, 2, size=(n_new_samples,))
938 learner = modAL.models.learners.ActiveLearner(
939 estimator=mock.MockEstimator(),
940 X_training=X_initial, y_training=y_initial
941 )
942 learner._add_training_data(X_new, y_new)
943 np.testing.assert_almost_equal(
944 learner.X_training,
945 np.vstack((X_initial, X_new))
946 )
947 np.testing.assert_equal(
948 learner.y_training,
949 np.concatenate((y_initial, y_new))
950 )
951 # 2. vector class labels
952 y_initial = np.random.randint(
953 0, 2, size=(n_samples, n_features+1))
954 y_new = np.random.randint(
955 0, 2, size=(n_new_samples, n_features+1))
956 learner = modAL.models.learners.ActiveLearner(
957 estimator=mock.MockEstimator(),
958 X_training=X_initial, y_training=y_initial
959 )
960 learner._add_training_data(X_new, y_new)
961 np.testing.assert_equal(
962 learner.y_training,
963 np.concatenate((y_initial, y_new))
964 )
965 # 3. data with shape (n, )
966 X_initial = np.random.rand(n_samples, )
967 y_initial = np.random.randint(0, 2, size=(n_samples,))
968 learner = modAL.models.learners.ActiveLearner(
969 estimator=mock.MockEstimator(),
970 X_training=X_initial, y_training=y_initial
971 )
972 X_new = np.random.rand(n_new_samples,)
973 y_new = np.random.randint(0, 2, size=(n_new_samples,))
974 learner._add_training_data(X_new, y_new)
975
976 # testing for invalid cases
977 # 1. len(X_new) != len(y_new)
978 X_new = np.random.rand(n_new_samples, n_features)
979 y_new = np.random.randint(0, 2, size=(2*n_new_samples,))
980 self.assertRaises(
981 ValueError, learner._add_training_data, X_new, y_new)
982 # 2. X_new has wrong dimensions
983 X_new = np.random.rand(n_new_samples, 2*n_features)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…