Пример #1
0
    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])}

        knn = KNN()
        knn.fit(EncodedData(sparse.csr_matrix(x), y), "default")

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

        pickle_file_path = path / "knn.pickle"
        with pickle_file_path.open("wb") as file:
            pickle.dump(knn.get_model(), file)

        knn2 = KNN()
        knn2.load(path)

        self.assertTrue(isinstance(knn2.get_model(), KNeighborsClassifier))

        shutil.rmtree(path)
Пример #2
0
    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])}

        knn = KNN()
        knn.fit(EncodedData(examples=sparse.csr_matrix(x), labels=y), Label("default"))

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

        with open(path / "knn.pickle", "wb") as file:
            pickle.dump(knn.model, file)

        config = MLMethodConfiguration()
        config.labels_with_values = {"default": [0, 1, 2]}
        config.store(path / "config.json")

        knn2 = KNN()
        knn2.load(path)

        self.assertTrue(isinstance(knn2.model, KNeighborsClassifier))

        shutil.rmtree(path)