eland.ml.MLModel.predict#
- MLModel.predict(X: Union[ArrayLike, List[float], List[List[float]]]) ArrayLike #
Make a prediction using a trained model stored in Elasticsearch.
Parameters for this method are not yet fully compatible with standard sklearn.predict.
Parameters#
- X: Input feature vector.
Must be either a numpy ndarray or a list or list of lists of type float. TODO: support DataFrame and other formats
Returns#
y: np.ndarray of dtype float for regressors or int for classifiers
Examples#
>>> from sklearn import datasets >>> from xgboost import XGBRegressor >>> from eland.ml import MLModel
>>> # Train model >>> training_data = datasets.make_classification(n_features=6, random_state=0) >>> test_data = [[-1, -2, -3, -4, -5, -6], [10, 20, 30, 40, 50, 60]] >>> regressor = XGBRegressor(objective='reg:squarederror') >>> regressor = regressor.fit(training_data[0], training_data[1])
>>> # Get some test results >>> regressor.predict(np.array(test_data)) array([0.06062475, 0.9990102 ], dtype=float32)
>>> # Serialise the model to Elasticsearch >>> feature_names = ["f0", "f1", "f2", "f3", "f4", "f5"] >>> model_id = "test_xgb_regressor" >>> es_model = MLModel.import_model('http://localhost:9200', model_id, regressor, feature_names, es_if_exists='replace')
>>> # Get some test results from Elasticsearch model >>> es_model.predict(test_data) array([0.0606248 , 0.99901026], dtype=float32)
>>> # Delete model from Elasticsearch >>> es_model.delete_model()