如今可以对xboost框架停止模型训练后,将模型部署到Elasticsearch,就可以直接完成对数据的预测了。一切很简单。
>>> from xgboost import XGBClassifier>>> from eland.ml import ImportedMLModel# Train and exercise an XGBoost ML model locally>>> xgb_model = XGBClassifier(booster="gbtree")>>> xgb_model.fit(training_data[0], training_data[1])>>> xgb_model.predict(training_data[0])[0 1 1 0 1 0 0 0 1 0]# Import the model into Elasticsearch>>> es_model = ImportedMLModel(es_client="localhost:9200",model_id="xgb-classifier",model=xgb_model,feature_names=["f0", "f1", "f2", "f3", "f4"],)# Exercise the ML model in Elasticsearch with the training data>>> es_model.predict(training_data[0])[0 1 1 0 1 0 0 0 1 0] 结束语