eland.ml.MLModel.predict#
- MLModel.predict(X: Union[ArrayLike, List[float], List[List[float]]]) ArrayLike #
使用存储在 Elasticsearch 中的训练模型进行预测。
此方法的参数尚未完全与标准 sklearn.predict 兼容。
参数#
- X: 输入特征向量。
必须是 numpy ndarray 或者 float 类型的列表或列表的列表。TODO: 支持 DataFrame 和其他格式
返回值#
y: 回归器为 dtype float 的 np.ndarray 或者分类器为 int 的 np.ndarray
示例#
>>> 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()