mirror of
https://github.com/elastic/eland.git
synced 2025-07-11 00:02:14 +08:00
7.6.0a3 (#131)
* Updating test matrix for 7.6 + removing oss for now. * Resolving 7.6.0 docs issues * Updating ML docs * Bumping version following doc fixes * Change ExternalMLModel to ImportedMLModel
This commit is contained in:
parent
fa930b6cea
commit
1a90e9232e
@ -753,7 +753,7 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"<eland.index.Index at 0x11631ffd0>"
|
"<eland.index.Index at 0x116b3efd0>"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 17,
|
"execution_count": 17,
|
||||||
@ -2704,15 +2704,15 @@
|
|||||||
" </tr>\n",
|
" </tr>\n",
|
||||||
" <tr>\n",
|
" <tr>\n",
|
||||||
" <th>25%</th>\n",
|
" <th>25%</th>\n",
|
||||||
" <td>410.011039</td>\n",
|
" <td>410.008918</td>\n",
|
||||||
" <td>2470.545974</td>\n",
|
" <td>2470.545974</td>\n",
|
||||||
" <td>...</td>\n",
|
" <td>...</td>\n",
|
||||||
" <td>251.773003</td>\n",
|
" <td>251.938710</td>\n",
|
||||||
" <td>1.000000</td>\n",
|
" <td>1.000000</td>\n",
|
||||||
" </tr>\n",
|
" </tr>\n",
|
||||||
" <tr>\n",
|
" <tr>\n",
|
||||||
" <th>50%</th>\n",
|
" <th>50%</th>\n",
|
||||||
" <td>640.387285</td>\n",
|
" <td>640.362667</td>\n",
|
||||||
" <td>7612.072403</td>\n",
|
" <td>7612.072403</td>\n",
|
||||||
" <td>...</td>\n",
|
" <td>...</td>\n",
|
||||||
" <td>503.148975</td>\n",
|
" <td>503.148975</td>\n",
|
||||||
@ -2720,11 +2720,11 @@
|
|||||||
" </tr>\n",
|
" </tr>\n",
|
||||||
" <tr>\n",
|
" <tr>\n",
|
||||||
" <th>75%</th>\n",
|
" <th>75%</th>\n",
|
||||||
" <td>842.213490</td>\n",
|
" <td>840.617448</td>\n",
|
||||||
" <td>9734.960478</td>\n",
|
" <td>9738.206675</td>\n",
|
||||||
" <td>...</td>\n",
|
" <td>...</td>\n",
|
||||||
" <td>720.505705</td>\n",
|
" <td>720.026320</td>\n",
|
||||||
" <td>4.172535</td>\n",
|
" <td>4.160448</td>\n",
|
||||||
" </tr>\n",
|
" </tr>\n",
|
||||||
" <tr>\n",
|
" <tr>\n",
|
||||||
" <th>max</th>\n",
|
" <th>max</th>\n",
|
||||||
@ -2745,9 +2745,9 @@
|
|||||||
"mean 628.253689 7092.142457 ... 511.127842 2.835975\n",
|
"mean 628.253689 7092.142457 ... 511.127842 2.835975\n",
|
||||||
"std 266.386661 4578.263193 ... 334.741135 1.939365\n",
|
"std 266.386661 4578.263193 ... 334.741135 1.939365\n",
|
||||||
"min 100.020531 0.000000 ... 0.000000 0.000000\n",
|
"min 100.020531 0.000000 ... 0.000000 0.000000\n",
|
||||||
"25% 410.011039 2470.545974 ... 251.773003 1.000000\n",
|
"25% 410.008918 2470.545974 ... 251.938710 1.000000\n",
|
||||||
"50% 640.387285 7612.072403 ... 503.148975 3.000000\n",
|
"50% 640.362667 7612.072403 ... 503.148975 3.000000\n",
|
||||||
"75% 842.213490 9734.960478 ... 720.505705 4.172535\n",
|
"75% 840.617448 9738.206675 ... 720.026320 4.160448\n",
|
||||||
"max 1199.729004 19881.482422 ... 1902.901978 6.000000\n",
|
"max 1199.729004 19881.482422 ... 1902.901978 6.000000\n",
|
||||||
"\n",
|
"\n",
|
||||||
"[8 rows x 7 columns]"
|
"[8 rows x 7 columns]"
|
||||||
|
@ -1023,21 +1023,21 @@
|
|||||||
" </tr>\n",
|
" </tr>\n",
|
||||||
" <tr>\n",
|
" <tr>\n",
|
||||||
" <th>25%</th>\n",
|
" <th>25%</th>\n",
|
||||||
" <td>14217.474239</td>\n",
|
" <td>14227.934845</td>\n",
|
||||||
" <td>1.000000</td>\n",
|
" <td>1.000000</td>\n",
|
||||||
" <td>1.250068</td>\n",
|
" <td>1.250000</td>\n",
|
||||||
" </tr>\n",
|
" </tr>\n",
|
||||||
" <tr>\n",
|
" <tr>\n",
|
||||||
" <th>50%</th>\n",
|
" <th>50%</th>\n",
|
||||||
" <td>15662.024630</td>\n",
|
" <td>15669.138235</td>\n",
|
||||||
" <td>2.000000</td>\n",
|
" <td>2.000000</td>\n",
|
||||||
" <td>2.510000</td>\n",
|
" <td>2.510000</td>\n",
|
||||||
" </tr>\n",
|
" </tr>\n",
|
||||||
" <tr>\n",
|
" <tr>\n",
|
||||||
" <th>75%</th>\n",
|
" <th>75%</th>\n",
|
||||||
" <td>17212.723881</td>\n",
|
" <td>17212.690092</td>\n",
|
||||||
" <td>6.671951</td>\n",
|
" <td>6.610262</td>\n",
|
||||||
" <td>4.210000</td>\n",
|
" <td>4.211297</td>\n",
|
||||||
" </tr>\n",
|
" </tr>\n",
|
||||||
" <tr>\n",
|
" <tr>\n",
|
||||||
" <th>max</th>\n",
|
" <th>max</th>\n",
|
||||||
@ -1055,9 +1055,9 @@
|
|||||||
"mean 15590.776680 7.464000 4.103233\n",
|
"mean 15590.776680 7.464000 4.103233\n",
|
||||||
"std 1764.025160 85.924387 20.104873\n",
|
"std 1764.025160 85.924387 20.104873\n",
|
||||||
"min 12347.000000 -9360.000000 0.000000\n",
|
"min 12347.000000 -9360.000000 0.000000\n",
|
||||||
"25% 14217.474239 1.000000 1.250068\n",
|
"25% 14227.934845 1.000000 1.250000\n",
|
||||||
"50% 15662.024630 2.000000 2.510000\n",
|
"50% 15669.138235 2.000000 2.510000\n",
|
||||||
"75% 17212.723881 6.671951 4.210000\n",
|
"75% 17212.690092 6.610262 4.211297\n",
|
||||||
"max 18239.000000 2880.000000 950.990000"
|
"max 18239.000000 2880.000000 950.990000"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
eland.ml.ExternalMLModel.predict
|
|
||||||
================================
|
|
||||||
|
|
||||||
.. currentmodule:: eland.ml
|
|
||||||
|
|
||||||
.. automethod:: ExternalMLModel.predict
|
|
@ -1,6 +0,0 @@
|
|||||||
eland.ml.ExternalMLModel
|
|
||||||
========================
|
|
||||||
|
|
||||||
.. currentmodule:: eland.ml
|
|
||||||
|
|
||||||
.. autoclass:: ExternalMLModel
|
|
@ -0,0 +1,6 @@
|
|||||||
|
eland.ml.ImportedMLModel.predict
|
||||||
|
================================
|
||||||
|
|
||||||
|
.. currentmodule:: eland.ml
|
||||||
|
|
||||||
|
.. automethod:: ImportedMLModel.predict
|
6
docs/source/reference/api/eland.ml.ImportedMLModel.rst
Normal file
6
docs/source/reference/api/eland.ml.ImportedMLModel.rst
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
eland.ml.ImportedMLModel
|
||||||
|
========================
|
||||||
|
|
||||||
|
.. currentmodule:: eland.ml
|
||||||
|
|
||||||
|
.. autoclass:: ImportedMLModel
|
@ -17,7 +17,7 @@ The fastest way to get started with machine learning features is to start a free
|
|||||||
|
|
||||||
See https://www.elastic.co/guide/en/machine-learning/current/setup.html and other documentation for more detail.
|
See https://www.elastic.co/guide/en/machine-learning/current/setup.html and other documentation for more detail.
|
||||||
|
|
||||||
ExternalMLModel
|
ImportedMLModel
|
||||||
~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~
|
||||||
.. currentmodule:: eland.ml
|
.. currentmodule:: eland.ml
|
||||||
|
|
||||||
@ -26,12 +26,12 @@ Constructor
|
|||||||
.. autosummary::
|
.. autosummary::
|
||||||
:toctree: api/
|
:toctree: api/
|
||||||
|
|
||||||
ExternalMLModel
|
ImportedMLModel
|
||||||
|
|
||||||
Learning API
|
Learning API
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
.. autosummary::
|
.. autosummary::
|
||||||
:toctree: api/
|
:toctree: api/
|
||||||
|
|
||||||
ExternalMLModel.predict
|
ImportedMLModel.predict
|
||||||
|
|
||||||
|
@ -13,4 +13,4 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from eland.ml.ml_model import *
|
from eland.ml.ml_model import *
|
||||||
from eland.ml.external_ml_model import *
|
from eland.ml.imported_ml_model import *
|
||||||
|
@ -28,7 +28,7 @@ from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
|
|||||||
from xgboost import XGBRegressor, XGBClassifier
|
from xgboost import XGBRegressor, XGBClassifier
|
||||||
|
|
||||||
|
|
||||||
class ExternalMLModel(MLModel):
|
class ImportedMLModel(MLModel):
|
||||||
"""
|
"""
|
||||||
Transform and serialize a trained 3rd party model into Elasticsearch.
|
Transform and serialize a trained 3rd party model into Elasticsearch.
|
||||||
This model can then be used for inference in the Elastic Stack.
|
This model can then be used for inference in the Elastic Stack.
|
||||||
@ -67,7 +67,7 @@ class ExternalMLModel(MLModel):
|
|||||||
--------
|
--------
|
||||||
>>> from sklearn import datasets
|
>>> from sklearn import datasets
|
||||||
>>> from sklearn.tree import DecisionTreeClassifier
|
>>> from sklearn.tree import DecisionTreeClassifier
|
||||||
>>> from eland.ml import ExternalMLModel
|
>>> from eland.ml import ImportedMLModel
|
||||||
|
|
||||||
>>> # Train model
|
>>> # Train model
|
||||||
>>> training_data = datasets.make_classification(n_features=5, random_state=0)
|
>>> training_data = datasets.make_classification(n_features=5, random_state=0)
|
||||||
@ -82,7 +82,7 @@ class ExternalMLModel(MLModel):
|
|||||||
>>> # Serialise the model to Elasticsearch
|
>>> # Serialise the model to Elasticsearch
|
||||||
>>> feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
>>> feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
||||||
>>> model_id = "test_decision_tree_classifier"
|
>>> model_id = "test_decision_tree_classifier"
|
||||||
>>> es_model = ExternalMLModel('localhost', model_id, classifier, feature_names, overwrite=True)
|
>>> es_model = ImportedMLModel('localhost', model_id, classifier, feature_names, overwrite=True)
|
||||||
|
|
||||||
>>> # Get some test results from Elasticsearch model
|
>>> # Get some test results from Elasticsearch model
|
||||||
>>> es_model.predict(test_data)
|
>>> es_model.predict(test_data)
|
||||||
@ -169,7 +169,7 @@ class ExternalMLModel(MLModel):
|
|||||||
--------
|
--------
|
||||||
>>> from sklearn import datasets
|
>>> from sklearn import datasets
|
||||||
>>> from xgboost import XGBRegressor
|
>>> from xgboost import XGBRegressor
|
||||||
>>> from eland.ml import ExternalMLModel
|
>>> from eland.ml import ImportedMLModel
|
||||||
|
|
||||||
>>> # Train model
|
>>> # Train model
|
||||||
>>> training_data = datasets.make_classification(n_features=6, random_state=0)
|
>>> training_data = datasets.make_classification(n_features=6, random_state=0)
|
||||||
@ -184,7 +184,7 @@ class ExternalMLModel(MLModel):
|
|||||||
>>> # Serialise the model to Elasticsearch
|
>>> # Serialise the model to Elasticsearch
|
||||||
>>> feature_names = ["f0", "f1", "f2", "f3", "f4", "f5"]
|
>>> feature_names = ["f0", "f1", "f2", "f3", "f4", "f5"]
|
||||||
>>> model_id = "test_xgb_regressor"
|
>>> model_id = "test_xgb_regressor"
|
||||||
>>> es_model = ExternalMLModel('localhost', model_id, regressor, feature_names, overwrite=True)
|
>>> es_model = ImportedMLModel('localhost', model_id, regressor, feature_names, overwrite=True)
|
||||||
|
|
||||||
>>> # Get some test results from Elasticsearch model
|
>>> # Get some test results from Elasticsearch model
|
||||||
>>> es_model.predict(test_data)
|
>>> es_model.predict(test_data)
|
@ -18,11 +18,11 @@ from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
|
|||||||
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
|
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
|
||||||
from xgboost import XGBRegressor, XGBClassifier
|
from xgboost import XGBRegressor, XGBClassifier
|
||||||
|
|
||||||
from eland.ml import ExternalMLModel
|
from eland.ml import ImportedMLModel
|
||||||
from eland.tests import ES_TEST_CLIENT
|
from eland.tests import ES_TEST_CLIENT
|
||||||
|
|
||||||
|
|
||||||
class TestExternalMLModel:
|
class TestImportedMLModel:
|
||||||
|
|
||||||
def test_decision_tree_classifier(self):
|
def test_decision_tree_classifier(self):
|
||||||
# Train model
|
# Train model
|
||||||
@ -38,7 +38,7 @@ class TestExternalMLModel:
|
|||||||
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
||||||
model_id = "test_decision_tree_classifier"
|
model_id = "test_decision_tree_classifier"
|
||||||
|
|
||||||
es_model = ExternalMLModel(ES_TEST_CLIENT, model_id, classifier, feature_names, overwrite=True)
|
es_model = ImportedMLModel(ES_TEST_CLIENT, model_id, classifier, feature_names, overwrite=True)
|
||||||
es_results = es_model.predict(test_data)
|
es_results = es_model.predict(test_data)
|
||||||
|
|
||||||
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
||||||
@ -60,7 +60,7 @@ class TestExternalMLModel:
|
|||||||
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
||||||
model_id = "test_decision_tree_regressor"
|
model_id = "test_decision_tree_regressor"
|
||||||
|
|
||||||
es_model = ExternalMLModel(ES_TEST_CLIENT, model_id, regressor, feature_names, overwrite=True)
|
es_model = ImportedMLModel(ES_TEST_CLIENT, model_id, regressor, feature_names, overwrite=True)
|
||||||
es_results = es_model.predict(test_data)
|
es_results = es_model.predict(test_data)
|
||||||
|
|
||||||
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
||||||
@ -82,7 +82,7 @@ class TestExternalMLModel:
|
|||||||
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
||||||
model_id = "test_random_forest_classifier"
|
model_id = "test_random_forest_classifier"
|
||||||
|
|
||||||
es_model = ExternalMLModel(ES_TEST_CLIENT, model_id, classifier, feature_names, overwrite=True)
|
es_model = ImportedMLModel(ES_TEST_CLIENT, model_id, classifier, feature_names, overwrite=True)
|
||||||
es_results = es_model.predict(test_data)
|
es_results = es_model.predict(test_data)
|
||||||
|
|
||||||
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
||||||
@ -104,7 +104,7 @@ class TestExternalMLModel:
|
|||||||
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
||||||
model_id = "test_random_forest_regressor"
|
model_id = "test_random_forest_regressor"
|
||||||
|
|
||||||
es_model = ExternalMLModel(ES_TEST_CLIENT, model_id, regressor, feature_names, overwrite=True)
|
es_model = ImportedMLModel(ES_TEST_CLIENT, model_id, regressor, feature_names, overwrite=True)
|
||||||
es_results = es_model.predict(test_data)
|
es_results = es_model.predict(test_data)
|
||||||
|
|
||||||
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
||||||
@ -126,7 +126,7 @@ class TestExternalMLModel:
|
|||||||
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
||||||
model_id = "test_xgb_classifier"
|
model_id = "test_xgb_classifier"
|
||||||
|
|
||||||
es_model = ExternalMLModel(ES_TEST_CLIENT, model_id, classifier, feature_names, overwrite=True)
|
es_model = ImportedMLModel(ES_TEST_CLIENT, model_id, classifier, feature_names, overwrite=True)
|
||||||
es_results = es_model.predict(test_data)
|
es_results = es_model.predict(test_data)
|
||||||
|
|
||||||
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
||||||
@ -148,7 +148,7 @@ class TestExternalMLModel:
|
|||||||
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
feature_names = ["f0", "f1", "f2", "f3", "f4"]
|
||||||
model_id = "test_xgb_regressor"
|
model_id = "test_xgb_regressor"
|
||||||
|
|
||||||
es_model = ExternalMLModel(ES_TEST_CLIENT, model_id, regressor, feature_names, overwrite=True)
|
es_model = ImportedMLModel(ES_TEST_CLIENT, model_id, regressor, feature_names, overwrite=True)
|
||||||
es_results = es_model.predict(test_data)
|
es_results = es_model.predict(test_data)
|
||||||
|
|
||||||
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
np.testing.assert_almost_equal(test_results, es_results, decimal=4)
|
Loading…
x
Reference in New Issue
Block a user