def test_predict(self): x = np.array([[1, 0, 0], [0, 1, 1], [1, 1, 1], [0, 1, 1]]) y = {"test": np.array([1, 0, 2, 0])} svm = SVM() svm.fit(EncodedData(x, y), "test") test_x = np.array([[0, 1, 0], [1, 0, 0]]) y = svm.predict(EncodedData(test_x), 'test')["test"] self.assertTrue(len(y) == 2) self.assertTrue(y[0] in [0, 1, 2]) self.assertTrue(y[1] in [0, 1, 2])
def test_store(self): x = np.array([[1, 0, 0], [0, 1, 1], [1, 1, 1], [0, 1, 1]]) y = {"default": np.array(['a', "b", "c", "a"])} svm = SVM() svm.fit(EncodedData(x, y), 'default') path = EnvironmentSettings.root_path / "my_svm/" svm.store(path) self.assertTrue(os.path.isfile(path / "svm.pickle")) with open(path / "svm.pickle", "rb") as file: svm2 = pickle.load(file) self.assertTrue(isinstance(svm2, SVC)) shutil.rmtree(path)
def test_load(self): x = np.array([[1, 0, 0], [0, 1, 1], [1, 1, 1], [0, 1, 1]]) y = {"default": np.array([1, 0, 2, 0])} svm = SVM() svm.fit(EncodedData(x, y), 'default') path = EnvironmentSettings.tmp_test_path / "my_svm2/" PathBuilder.build(path) with open(path / "svm.pickle", "wb") as file: pickle.dump(svm.get_model(), file) svm2 = SVM() svm2.load(path) self.assertTrue(isinstance(svm2.get_model(), SVC)) shutil.rmtree(path)
def test_fit(self): x = np.array([[1, 0, 0], [0, 1, 1], [1, 1, 1], [0, 1, 1]]) y = {"default": np.array([1, 0, 2, 0])} svm = SVM() svm.fit(EncodedData(x, y), 'default')