Beispiel #1
0
    def test_numpy(self):
        try:
            import numpy as np
            model = Model.load('./resources/models/single_iris_dectree.xml')

            # Data in 1-D
            result = model.predict(np.array([5.1, 3.5, 1.4, 0.2]))
            self.assertEqual(result[0], 'Iris-setosa')
            self.assertEqual(result[1], 1.0)
            self.assertEqual(result[2], 1.0)
            self.assertEqual(result[3], 0.0)
            self.assertEqual(result[4], 0.0)
            self.assertEqual(result[5], '1')

            # Data in 2-D
            result = model.predict(
                np.array([[5.1, 3.5, 1.4, 0.2], [7, 3.2, 4.7, 1.4]]))
            self.assertEqual(len(result), 2)
            self.assertEqual(result[0][0], 'Iris-setosa')
            self.assertEqual(result[0][1], 1.0)
            self.assertEqual(result[0][2], 1.0)
            self.assertEqual(result[0][3], 0.0)
            self.assertEqual(result[0][4], 0.0)
            self.assertEqual(result[0][5], '1')
            self.assertEqual(result[1][0], 'Iris-versicolor')
            self.assertEqual(result[1][1], 0.9074074074074074)
            self.assertEqual(result[1][2], 0.0)
            self.assertEqual(result[1][3], 0.9074074074074074)
            self.assertEqual(result[1][4], 0.09259259259259259)
            self.assertEqual(result[1][5], '3')

        except ImportError:
            pass
Beispiel #2
0
    def test_pandas(self):
        try:
            import pandas as pd
            model = Model.load('./resources/models/single_iris_dectree.xml')

            # Data in Series
            result = model.predict(
                pd.Series({
                    'sepal_length': 5.1,
                    'sepal_width': 3.5,
                    'petal_length': 1.4,
                    'petal_width': 0.2
                }))
            self.assertEqual(result.get('predicted_class'), 'Iris-setosa')
            self.assertEqual(result.get('probability'), 1.0)
            self.assertEqual(result.get('node_id'), '1')

            # Data in DataFrame
            data = pd.read_csv('./resources/data/Iris.csv')
            result = model.predict(data)
            self.assertEqual(result.iloc[0].get('predicted_class'),
                             'Iris-setosa')
            self.assertEqual(result.iloc[0].get('probability'), 1.0)
            self.assertEqual(result.iloc[0].get('node_id'), '1')
        except ImportError:
            pass
Beispiel #3
0
 def load(self) -> bool:
     model_path = kfserving.Storage.download(self.model_dir)
     paths = [os.path.join(model_path, MODEL_BASENAME + model_extension)
              for model_extension in MODEL_EXTENSIONS]
     for path in paths:
         if os.path.exists(path):
             self._model = Model.load(path)
             self.ready = True
             break
     return self.ready
Beispiel #4
0
    def test_load(self):
        file_path = './resources/models/single_iris_dectree.xml'
        self.assertTrue(Model.load(file_path) is not None)

        with open(file_path, 'rb') as f:
            self.assertTrue(Model.load(f) is not None)

        with open(file_path) as f:
            self.assertTrue(Model.load(f) is not None)

        with open(file_path, 'rb') as f:
            s = f.read()
            self.assertTrue(Model.load(s) is not None)
            s = bytearray(s)
            self.assertTrue(Model.load(s) is not None)

        with open(file_path) as f:
            s = f.read()
            self.assertTrue(Model.load(s) is not None)
def load_model_from_file(path):
    return Model.load(path)
Beispiel #6
0
def load_model():
    """Returns the pmml model"""
    model_path = pkg_resources.resource_stream(
        __name__, "models/pydamage_glm_model.pmml")
    model = Model.load(model_path)
    return model
    def load_model_from_artifact(self, artifact_path):
        from pypmml import Model

        model = Model.load(artifact_path)

        return model