Beispiel #1
0
    def test_load(self):
        x, y, encoded_data = self._prepare_data()

        cls = TCRdistClassifier(0.75)
        cls.fit(encoded_data, label_name="test", cores_for_training=4)

        path = PathBuilder.build(EnvironmentSettings.root_path / "test/tmp/tcrdist_classifier_load/")

        with open(path / "tcrdist_classifier.pickle", "wb") as file:
            dill.dump(cls.get_model(), file)

        cls2 = TCRdistClassifier(percentage=1.)
        cls2.load(path)

        self.assertTrue(isinstance(cls2.get_model(), KNeighborsClassifier))
        self.assertTrue(isinstance(cls2, TCRdistClassifier))
        self.assertEqual(3, cls2.model.n_neighbors)

        shutil.rmtree(path)
Beispiel #2
0
    def test_fit(self):
        x, y, encoded_data = self._prepare_data()
        knn = TCRdistClassifier(percentage=0.75)
        knn.fit(encoded_data, "test", cores_for_training=4)
        predictions = knn.predict(encoded_data, 'test')
        self.assertTrue(np.array_equal(y["test"], predictions["test"]))

        encoded_data.examples = np.array([[1.1, 0.1, 0.9, 1.9]])
        predictions = knn.predict(encoded_data, 'test')
        self.assertTrue(np.array_equal([0], predictions["test"]))
Beispiel #3
0
    def test_store(self):
        x, y, encoded_data = self._prepare_data()

        cls = TCRdistClassifier(0.75)
        cls.fit(encoded_data, label_name="test", cores_for_training=4)

        path = EnvironmentSettings.root_path / "test/tmp/tcrdist_classifier/"

        cls.store(path)
        self.assertTrue(os.path.isfile(path / "tcrdist_classifier.pickle"))

        with open(path / "tcrdist_classifier.pickle", "rb") as file:
            cls2 = pickle.load(file)

        self.assertTrue(isinstance(cls2, KNeighborsClassifier))

        shutil.rmtree(path)