MLModel.
import_model
Transform and serialize a trained 3rd party model into Elasticsearch. This model can then be used for inference in the Elastic Stack.
elasticsearch-py parameters or
elasticsearch-py instance
The unique identifier of the trained inference model in Elasticsearch.
sklearn.tree.DecisionTreeClassifier
sklearn.tree.DecisionTreeRegressor
sklearn.ensemble.RandomForestRegressor
sklearn.ensemble.RandomForestClassifier
Categorical fields are expected to already be processed
“regression”
“regression_l1”
“huber”
“fair”
“quantile”
“mape”
“binary”
“multiclass”
“multiclassova”
“binary:logistic”
“multi:softmax”
“multi:softprob”
“reg:squarederror”
“reg:linear”
“reg:squaredlogerror”
“reg:logistic”
“reg:pseudohubererror”
Names of the features (required)
Labels of the classification targets
Weights of the classification targets
How to behave if model already exists
fail: Raise a Value Error
replace: Overwrite existing model
If True will use ‘compressed_definition’ which uses gzipped JSON instead of raw JSON to reduce the amount of data sent over the wire in HTTP requests. Defaults to ‘True’.
Examples
>>> from sklearn import datasets >>> from sklearn.tree import DecisionTreeClassifier >>> from eland.ml import MLModel
>>> # 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 = MLModel.import_model( ... 'localhost', ... model_id=model_id, ... model=classifier, ... feature_names=feature_names, ... es_if_exists='replace' ... )
>>> # Get some test results from Elasticsearch model >>> es_model.predict(test_data) array([0, 1])
>>> # Delete model from Elasticsearch >>> es_model.delete_model()