.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_boosting.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_boosting.py: ====================== Default DL85Booster ====================== .. GENERATED FROM PYTHON SOURCE LINES 7-56 .. rst-class:: sphx-glr-script-out .. code-block:: none ###################################################################### # DL8.5 boosting classifier # ###################################################################### <<=== Optiboost ===>> Model building... Model built. Duration of building = 4.0266 Number of trees = 21 Confusion Matrix below [[ 18 16] [ 11 118]] Accuracy DL85Booster + MODEL_LP_DEMIRIZ on training set = 0.8798 Accuracy DL85Booster + MODEL_LP_DEMIRIZ on test set = 0.8344 <<=== AdaBoost + CART ===>> Model building... /home/docs/.asdf/installs/python/3.9.15/lib/python3.9/site-packages/sklearn/ensemble/_base.py:166: FutureWarning: `base_estimator` was renamed to `estimator` in version 1.2 and will be removed in 1.4. warnings.warn( Model built. Duration of building = 0.0489 Confusion Matrix below [[ 19 15] [ 7 122]] Accuracy AdaBoost on training set = 0.8659 Accuracy AdaBoost on test set = 0.865 <<=== Optiboost ===>> Model building... Model built. Duration of building = 5.8645 Number of trees = 47 Confusion Matrix below [[ 14 20] [ 6 123]] Accuracy DL85Booster + MODEL_LP_RATSCH on training set = 0.8367 Accuracy DL85Booster + MODEL_LP_RATSCH on test set = 0.8405 <<=== AdaBoost + CART ===>> Model building... /home/docs/.asdf/installs/python/3.9.15/lib/python3.9/site-packages/sklearn/ensemble/_base.py:166: FutureWarning: `base_estimator` was renamed to `estimator` in version 1.2 and will be removed in 1.4. warnings.warn( Model built. Duration of building = 0.1268 Confusion Matrix below [[ 20 14] [ 6 123]] Accuracy AdaBoost on training set = 0.8875 Accuracy AdaBoost on test set = 0.8773 <<=== Optiboost ===>> Model building... Model built. Duration of building = 13.4156 Number of trees = 34 Confusion Matrix below [[ 16 18] [ 4 125]] Accuracy DL85Booster + MODEL_QP_MDBOOST on training set = 0.8844 Accuracy DL85Booster + MODEL_QP_MDBOOST on test set = 0.865 <<=== AdaBoost + CART ===>> Model building... /home/docs/.asdf/installs/python/3.9.15/lib/python3.9/site-packages/sklearn/ensemble/_base.py:166: FutureWarning: `base_estimator` was renamed to `estimator` in version 1.2 and will be removed in 1.4. warnings.warn( Model built. Duration of building = 0.0783 Confusion Matrix below [[ 20 14] [ 5 124]] Accuracy AdaBoost on training set = 0.8844 Accuracy AdaBoost on test set = 0.8834 | .. code-block:: default import time import numpy as np from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score, confusion_matrix from sklearn.ensemble import AdaBoostClassifier from sklearn.tree import DecisionTreeClassifier from pydl85 import DL85Booster, Boosting_Model dataset = np.genfromtxt("../datasets/anneal.txt", delimiter=' ') X, y = dataset[:, 1:], dataset[:, 0] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0) models = [Boosting_Model.MODEL_LP_DEMIRIZ, Boosting_Model.MODEL_LP_RATSCH, Boosting_Model.MODEL_QP_MDBOOST] regulators = [15] * len(models) model_names = ['MODEL_LP_DEMIRIZ', 'MODEL_LP_RATSCH', 'MODEL_QP_MDBOOST'] depth = 1 print("######################################################################\n" "# DL8.5 boosting classifier #\n" "######################################################################") for i, model in enumerate(models): print("<<=== Optiboost ===>>") db_clf = DL85Booster(max_depth=depth, regulator=regulators[i], model=model) start = time.perf_counter() print("Model building...") db_clf.fit(X_train, y_train) duration = time.perf_counter() - start print("Model built. Duration of building =", round(duration, 4)) print("Number of trees =", db_clf.n_estimators_) y_pred = db_clf.predict(X_test) print("Confusion Matrix below") print(confusion_matrix(y_test, y_pred)) print("Accuracy DL85Booster +", model_names[i], "on training set =", round(accuracy_score(y_train, db_clf.predict(X_train)), 4)) print("Accuracy DL85Booster +", model_names[i], "on test set =", round(accuracy_score(y_test, y_pred), 4), "\n") print("<<=== AdaBoost + CART ===>>") ab_clf = AdaBoostClassifier(base_estimator=DecisionTreeClassifier(max_depth=depth), n_estimators=db_clf.n_estimators_) start = time.perf_counter() print("Model building...") ab_clf.fit(X_train, y_train) duration = time.perf_counter() - start print("Model built. Duration of building =", round(duration, 4)) y_pred = ab_clf.predict(X_test) print("Confusion Matrix below") print(confusion_matrix(y_test, y_pred)) print("Accuracy AdaBoost on training set =", round(accuracy_score(y_train, ab_clf.predict(X_train)), 4)) print("Accuracy AdaBoost on test set =", round(accuracy_score(y_test, y_pred), 4)) print("\n\n") .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 24.127 seconds) .. _sphx_glr_download_auto_examples_plot_boosting.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_boosting.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_boosting.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_