eland.ml.ImportedMLModel

class eland.ml.ImportedMLModel(es_client, model_id: str, model: Union[sklearn.tree._classes.DecisionTreeClassifier, sklearn.tree._classes.DecisionTreeRegressor, sklearn.ensemble._forest.RandomForestRegressor, sklearn.ensemble._forest.RandomForestClassifier, xgboost.sklearn.XGBClassifier, xgboost.sklearn.XGBRegressor], feature_names: List[str], classification_labels: List[str] = None, classification_weights: List[float] = None, overwrite=False)

Transform and serialize a trained 3rd party model into Elasticsearch. This model can then be used for inference in the Elastic Stack.

Parameters:
es_client: Elasticsearch client argument(s)
  • elasticsearch-py parameters or
  • elasticsearch-py instance or
  • eland.Client instance
model_id: str

The unique identifier of the trained inference model in Elasticsearch.

model: An instance of a supported python model. We support the following model types:
  • sklearn.tree.DecisionTreeClassifier
  • sklearn.tree.DecisionTreeRegressor
  • sklearn.ensemble.RandomForestRegressor
  • sklearn.ensemble.RandomForestClassifier
  • xgboost.XGBClassifier
  • xgboost.XGBRegressor
feature_names: List[str]

Names of the features (required)

classification_labels: List[str]

Labels of the classification targets

classification_weights: List[str]

Weights of the classification targets

overwrite: bool

Delete and overwrite existing model (if exists)

Examples

>>> from sklearn import datasets
>>> from sklearn.tree import DecisionTreeClassifier
>>> from eland.ml import ImportedMLModel
>>> # Train model
>>> training_data = datasets.make_classification(n_features=5, random_state=0)
>>> test_data = [[-50.1, 0.2, 0.3, -0.5, 1.0], [1.6, 2.1, -10, 50, -1.0]]
>>> classifier = DecisionTreeClassifier()
>>> classifier = classifier.fit(training_data[0], training_data[1])
>>> # Get some test results
>>> classifier.predict(test_data)
array([0, 1])
>>> # Serialise the model to Elasticsearch
>>> feature_names = ["f0", "f1", "f2", "f3", "f4"]
>>> model_id = "test_decision_tree_classifier"
>>> es_model = ImportedMLModel('localhost', model_id, classifier, feature_names, overwrite=True)
>>> # Get some test results from Elasticsearch model
>>> es_model.predict(test_data)
array([0, 1])
>>> # Delete model from Elasticsearch
>>> es_model.delete_model()