|
1 |
| -.. ****************************************************************************** |
2 |
| -.. * Copyright 2023 Intel Corporation |
3 |
| -.. * |
4 |
| -.. * Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
| -.. * you may not use this file except in compliance with the License. |
6 |
| -.. * You may obtain a copy of the License at |
7 |
| -.. * |
8 |
| -.. * http://www.apache.org/licenses/LICENSE-2.0 |
9 |
| -.. * |
10 |
| -.. * Unless required by applicable law or agreed to in writing, software |
11 |
| -.. * distributed under the License is distributed on an "AS IS" BASIS, |
12 |
| -.. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
| -.. * See the License for the specific language governing permissions and |
14 |
| -.. * limitations under the License. |
15 |
| -.. *******************************************************************************/ |
16 |
| -
|
17 |
| -.. _model-builders: |
18 |
| - |
19 |
| -############################################### |
20 |
| -Model Builders for the Gradient Boosting Frameworks |
21 |
| -############################################### |
22 |
| -Introduction |
23 |
| ------------------- |
24 |
| -Gradient boosting on decision trees is one of the most accurate and efficient |
25 |
| -machine learning algorithms for classification and regression. |
26 |
| -The most popular implementations of it are the XGBoost*, |
27 |
| -LightGBM*, and CatBoost* frameworks. |
28 |
| -daal4py Model Builders deliver the accelerated |
29 |
| -models inference of those frameworks. The inference is performed by the oneDAL GBT implementation tuned |
30 |
| -for the best performance on the Intel(R) Architecture. |
31 |
| - |
32 |
| -Conversion |
33 |
| ---------- |
34 |
| -The first step is to convert already trained model. There are similar |
35 |
| -APIs for different frameworks. |
36 |
| -XGBoost:: |
37 |
| - |
38 |
| - import daal4py as d4p |
39 |
| - d4p_model = d4p.get_gbt_model_from_xgboost(xgb_model) |
40 |
| - |
41 |
| -LightGBM:: |
42 |
| - |
43 |
| - import daal4py as d4p |
44 |
| - d4p_model = d4p.get_gbt_model_from_lightgbm(lgb_model) |
45 |
| - |
46 |
| -CatBoost:: |
47 |
| - |
48 |
| - import daal4py as d4p |
49 |
| - d4p_model = d4p.get_gbt_model_from_catboost(cb_model) |
50 |
| - |
51 |
| -.. note:: Convert model only once and then use it for the inference. |
52 |
| - |
53 |
| -Classification and Regression Inference |
54 |
| ---------- |
55 |
| -GBT implementation in daal4py assumes separate APIs for the classification and regression. |
56 |
| -Specify the corresponding API and match the corresponding problem |
57 |
| -in the initial framework. |
58 |
| - |
59 |
| -Classification:: |
60 |
| - |
61 |
| - d4p_cls_algo = d4p.gbt_classification_prediction( |
62 |
| - nClasses=params['classes_count'], |
63 |
| - resultsToEvaluate="computeClassLabels", |
64 |
| - fptype='float' |
65 |
| - ) |
66 |
| - |
67 |
| -Regression:: |
68 |
| - |
69 |
| - d4p_reg_algo = d4p.gbt_regression_prediction() |
70 |
| - |
71 |
| -Next, daal4py algorithm object needs compute method to be called. |
72 |
| -Both the data and the previously converted model should be passed with the results of the prediction |
73 |
| -available within the ``.prediction`` parameter. |
74 |
| - |
75 |
| -Compute:: |
76 |
| - |
77 |
| - d4p_predictions = d4p_reg_algo.compute(X_test, d4p_model).prediction |
78 |
| - |
79 |
| -The one-line variant of the same code:: |
80 |
| - |
81 |
| - d4p_prediction = d4p.gbt_regression_prediction().compute(X_test, d4p_model).prediction |
82 |
| - |
83 |
| - |
84 |
| -Limitations |
85 |
| ---------------------------------- |
86 |
| -Missing Values (NaN) |
87 |
| -Note that there is temporary limitation on the use of missing values |
88 |
| -(NaN) during training and prediction. This problem is addressed on |
89 |
| -the master branch and to be available in the 2023.2 release. |
90 |
| - |
91 |
| -Examples |
92 |
| ---------------------------------- |
93 |
| -Model Builders models conversion |
94 |
| - |
95 |
| -- `XGBoost model conversion <https://github.com/intel/scikit-learn-intelex/blob/master/examples/daal4py/gbt_cls_model_create_from_xgboost_batch.py>`_ |
96 |
| -- `LightGBM model conversion <https://github.com/intel/scikit-learn-intelex/blob/master/examples/daal4py/gbt_cls_model_create_from_lightgbm_batch.py>`_ |
97 |
| -- `CatBoost model conversion <https://github.com/intel/scikit-learn-intelex/blob/master/examples/daal4py/gbt_cls_model_create_from_catboost_batch.py>`_ |
98 |
| - |
99 |
| -Articles and Blog Posts |
100 |
| ---------------------------------- |
101 |
| - |
102 |
| -- `Improving the Performance of XGBoost and LightGBM Inference <https://medium.com/intel-analytics-software/improving-the-performance-of-xgboost-and-lightgbm-inference-3b542c03447e>`_ |
| 1 | +.. ****************************************************************************** |
| 2 | +.. * Copyright 2023 Intel Corporation |
| 3 | +.. * |
| 4 | +.. * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +.. * you may not use this file except in compliance with the License. |
| 6 | +.. * You may obtain a copy of the License at |
| 7 | +.. * |
| 8 | +.. * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +.. * |
| 10 | +.. * Unless required by applicable law or agreed to in writing, software |
| 11 | +.. * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +.. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +.. * See the License for the specific language governing permissions and |
| 14 | +.. * limitations under the License. |
| 15 | +.. *******************************************************************************/ |
| 16 | +
|
| 17 | +.. _model-builders: |
| 18 | + |
| 19 | +############################################### |
| 20 | +Model Builders for the Gradient Boosting Frameworks |
| 21 | +############################################### |
| 22 | + |
| 23 | +.. include:: note.rst |
| 24 | + |
| 25 | +Introduction |
| 26 | +------------------ |
| 27 | +Gradient boosting on decision trees is one of the most accurate and efficient |
| 28 | +machine learning algorithms for classification and regression. |
| 29 | +The most popular implementations of it are: |
| 30 | + |
| 31 | +* XGBoost* |
| 32 | +* LightGBM* |
| 33 | +* CatBoost* |
| 34 | + |
| 35 | +daal4py Model Builders deliver the accelerated |
| 36 | +models inference of those frameworks. The inference is performed by the oneDAL GBT implementation tuned |
| 37 | +for the best performance on the Intel(R) Architecture. |
| 38 | + |
| 39 | +Conversion |
| 40 | +--------- |
| 41 | +The first step is to convert already trained model. The |
| 42 | +API usage for different frameworks is the same: |
| 43 | + |
| 44 | +XGBoost:: |
| 45 | + |
| 46 | + import daal4py as d4p |
| 47 | + d4p_model = d4p.mb.convert_model(xgb_model) |
| 48 | + |
| 49 | +LightGBM:: |
| 50 | + |
| 51 | + import daal4py as d4p |
| 52 | + d4p_model = d4p.mb.convert_model(lgb_model) |
| 53 | + |
| 54 | +CatBoost:: |
| 55 | + |
| 56 | + import daal4py as d4p |
| 57 | + d4p_model = d4p.mb.convert_model(cb_model) |
| 58 | + |
| 59 | +.. note:: Convert model only once and then use it for the inference. |
| 60 | + |
| 61 | +Classification and Regression Inference |
| 62 | +---------------------------------------- |
| 63 | + |
| 64 | +The API is the same for classification and regression inference. |
| 65 | +Based on the original model passed to the ``convert_model``, ``d4p_prediction`` is either the classification or regression output. |
| 66 | + |
| 67 | + :: |
| 68 | + |
| 69 | + d4p_prediction = d4p_model.predict(test_data) |
| 70 | + |
| 71 | +Here, the ``predict()`` method of ``d4p_model`` is being used to make predictions on the ``test_data`` dataset. |
| 72 | +The ``d4p_prediction`` variable stores the predictions made by the ``predict()`` method. |
| 73 | + |
| 74 | +Scikit-learn-style Estimators |
| 75 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 76 | + |
| 77 | +You can also use the scikit-learn-style classes ``GBTDAALClassifier`` and ``GBTDAALRegressor`` to convert and infer your models. For example: |
| 78 | + |
| 79 | +:: |
| 80 | + |
| 81 | + from daal4py.sklearn.ensemble import GBTDAALRegressor |
| 82 | + reg = xgb.XGBRegressor() |
| 83 | + reg.fit(X, y) |
| 84 | + d4p_predt = GBTDAALRegressor.convert_model(reg).predict(X) |
| 85 | + |
| 86 | +Examples |
| 87 | +--------------------------------- |
| 88 | +Model Builders models conversion |
| 89 | + |
| 90 | +- `XGBoost model conversion <https://github.com/intel/scikit-learn-intelex/blob/master/examples/daal4py/model_builders_xgboost.py>`_ |
| 91 | +- `LightGBM model conversion <https://github.com/intel/scikit-learn-intelex/blob/master/examples/daal4py/model_builders_lightgbm.py>`_ |
| 92 | +- `CatBoost model conversion <https://github.com/intel/scikit-learn-intelex/blob/master/examples/daal4py/model_builders_catboost.py>`_ |
| 93 | + |
| 94 | +Articles and Blog Posts |
| 95 | +--------------------------------- |
| 96 | + |
| 97 | +- `Improving the Performance of XGBoost and LightGBM Inference <https://medium.com/intel-analytics-software/improving-the-performance-of-xgboost-and-lightgbm-inference-3b542c03447e>`_ |
0 commit comments