-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e14b5eb
commit c1251f9
Showing
1 changed file
with
249 additions
and
0 deletions.
There are no files selected for viewing
249 changes: 249 additions & 0 deletions
249
unifiedbooster/demo/thierrymoudiki_2024_08_01_unifiedbooster.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,249 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"provenance": [] | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"!pip install git+https://github.com/thierrymoudiki/unifiedbooster.git --upgrade" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "R9R4-y5Obsqm", | ||
"outputId": "dc0f73f7-576a-4505-be6e-e19548f92ddd" | ||
}, | ||
"execution_count": 1, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"Collecting git+https://github.com/thierrymoudiki/unifiedbooster.git\n", | ||
" Cloning https://github.com/thierrymoudiki/unifiedbooster.git to /tmp/pip-req-build-bfnp1r_b\n", | ||
" Running command git clone --filter=blob:none --quiet https://github.com/thierrymoudiki/unifiedbooster.git /tmp/pip-req-build-bfnp1r_b\n", | ||
" Resolved https://github.com/thierrymoudiki/unifiedbooster.git to commit e45d844a6745f244a88f5979c70924ed1afe3860\n", | ||
" Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | ||
"Requirement already satisfied: Cython in /usr/local/lib/python3.10/dist-packages (from unifiedbooster==0.1.2) (3.0.10)\n", | ||
"Requirement already satisfied: scikit-learn in /usr/local/lib/python3.10/dist-packages (from unifiedbooster==0.1.2) (1.3.2)\n", | ||
"Requirement already satisfied: xgboost in /usr/local/lib/python3.10/dist-packages (from unifiedbooster==0.1.2) (2.1.0)\n", | ||
"Requirement already satisfied: lightgbm in /usr/local/lib/python3.10/dist-packages (from unifiedbooster==0.1.2) (4.4.0)\n", | ||
"Collecting catboost (from unifiedbooster==0.1.2)\n", | ||
" Downloading catboost-1.2.5-cp310-cp310-manylinux2014_x86_64.whl.metadata (1.2 kB)\n", | ||
"Requirement already satisfied: graphviz in /usr/local/lib/python3.10/dist-packages (from catboost->unifiedbooster==0.1.2) (0.20.3)\n", | ||
"Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from catboost->unifiedbooster==0.1.2) (3.7.1)\n", | ||
"Requirement already satisfied: numpy>=1.16.0 in /usr/local/lib/python3.10/dist-packages (from catboost->unifiedbooster==0.1.2) (1.26.4)\n", | ||
"Requirement already satisfied: pandas>=0.24 in /usr/local/lib/python3.10/dist-packages (from catboost->unifiedbooster==0.1.2) (2.1.4)\n", | ||
"Requirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from catboost->unifiedbooster==0.1.2) (1.13.1)\n", | ||
"Requirement already satisfied: plotly in /usr/local/lib/python3.10/dist-packages (from catboost->unifiedbooster==0.1.2) (5.15.0)\n", | ||
"Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from catboost->unifiedbooster==0.1.2) (1.16.0)\n", | ||
"Requirement already satisfied: joblib>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from scikit-learn->unifiedbooster==0.1.2) (1.4.2)\n", | ||
"Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn->unifiedbooster==0.1.2) (3.5.0)\n", | ||
"Collecting nvidia-nccl-cu12 (from xgboost->unifiedbooster==0.1.2)\n", | ||
" Downloading nvidia_nccl_cu12-2.22.3-py3-none-manylinux2014_x86_64.whl.metadata (1.8 kB)\n", | ||
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas>=0.24->catboost->unifiedbooster==0.1.2) (2.8.2)\n", | ||
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=0.24->catboost->unifiedbooster==0.1.2) (2024.1)\n", | ||
"Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=0.24->catboost->unifiedbooster==0.1.2) (2024.1)\n", | ||
"Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->catboost->unifiedbooster==0.1.2) (1.2.1)\n", | ||
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->catboost->unifiedbooster==0.1.2) (0.12.1)\n", | ||
"Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->catboost->unifiedbooster==0.1.2) (4.53.1)\n", | ||
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->catboost->unifiedbooster==0.1.2) (1.4.5)\n", | ||
"Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->catboost->unifiedbooster==0.1.2) (24.1)\n", | ||
"Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->catboost->unifiedbooster==0.1.2) (9.4.0)\n", | ||
"Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->catboost->unifiedbooster==0.1.2) (3.1.2)\n", | ||
"Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from plotly->catboost->unifiedbooster==0.1.2) (9.0.0)\n", | ||
"Downloading catboost-1.2.5-cp310-cp310-manylinux2014_x86_64.whl (98.2 MB)\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m98.2/98.2 MB\u001b[0m \u001b[31m5.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25hDownloading nvidia_nccl_cu12-2.22.3-py3-none-manylinux2014_x86_64.whl (190.9 MB)\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m190.9/190.9 MB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25hBuilding wheels for collected packages: unifiedbooster\n", | ||
" Building wheel for unifiedbooster (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | ||
" Created wheel for unifiedbooster: filename=unifiedbooster-0.1.2-py3-none-any.whl size=3503 sha256=455d29c6105ffb4aa1251432e78831b2603e9db6bafe6d9e39d97f4526bb9fa9\n", | ||
" Stored in directory: /tmp/pip-ephem-wheel-cache-2a9_czka/wheels/ac/dd/dd/e6ca79dfbfe87388d253e5b727d1169c5b2f060bbb3620cd5f\n", | ||
"Successfully built unifiedbooster\n", | ||
"Installing collected packages: nvidia-nccl-cu12, catboost, unifiedbooster\n", | ||
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", | ||
"torch 2.3.1+cu121 requires nvidia-cublas-cu12==12.1.3.1; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", | ||
"torch 2.3.1+cu121 requires nvidia-cuda-cupti-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", | ||
"torch 2.3.1+cu121 requires nvidia-cuda-nvrtc-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", | ||
"torch 2.3.1+cu121 requires nvidia-cuda-runtime-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", | ||
"torch 2.3.1+cu121 requires nvidia-cudnn-cu12==8.9.2.26; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", | ||
"torch 2.3.1+cu121 requires nvidia-cufft-cu12==11.0.2.54; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", | ||
"torch 2.3.1+cu121 requires nvidia-curand-cu12==10.3.2.106; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", | ||
"torch 2.3.1+cu121 requires nvidia-cusolver-cu12==11.4.5.107; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", | ||
"torch 2.3.1+cu121 requires nvidia-cusparse-cu12==12.1.0.106; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", | ||
"torch 2.3.1+cu121 requires nvidia-nvtx-cu12==12.1.105; platform_system == \"Linux\" and platform_machine == \"x86_64\", which is not installed.\n", | ||
"torch 2.3.1+cu121 requires nvidia-nccl-cu12==2.20.5; platform_system == \"Linux\" and platform_machine == \"x86_64\", but you have nvidia-nccl-cu12 2.22.3 which is incompatible.\u001b[0m\u001b[31m\n", | ||
"\u001b[0mSuccessfully installed catboost-1.2.5 nvidia-nccl-cu12-2.22.3 unifiedbooster-0.1.2\n" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"import unifiedbooster as ub\n", | ||
"from sklearn.datasets import load_iris, load_breast_cancer, load_wine\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"from sklearn.metrics import accuracy_score\n", | ||
"\n", | ||
"datasets = [load_iris(), load_breast_cancer(), load_wine()]\n", | ||
"\n", | ||
"for dataset in datasets:\n", | ||
"\n", | ||
" X, y = dataset.data, dataset.target\n", | ||
" X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n", | ||
"\n", | ||
" # Initialize the unified regressor (example with XGBoost)\n", | ||
" regressor1 = ub.GBDTClassifier(model_type='xgboost')\n", | ||
" regressor2 = ub.GBDTClassifier(model_type='catboost')\n", | ||
" regressor3 = ub.GBDTClassifier(model_type='lightgbm')\n", | ||
"\n", | ||
" # Fit the model\n", | ||
" regressor1.fit(X_train, y_train)\n", | ||
" regressor2.fit(X_train, y_train)\n", | ||
" regressor3.fit(X_train, y_train)\n", | ||
"\n", | ||
" # Predict on the test set\n", | ||
" y_pred1 = regressor1.predict(X_test)\n", | ||
" y_pred2 = regressor2.predict(X_test)\n", | ||
" y_pred3 = regressor3.predict(X_test)\n", | ||
"\n", | ||
" # Evaluate the model\n", | ||
" accuracy1 = accuracy_score(y_test, y_pred1)\n", | ||
" accuracy2 = accuracy_score(y_test, y_pred2)\n", | ||
" accuracy3 = accuracy_score(y_test, y_pred3)\n", | ||
" print(f\"Classification Accuracy xgboost: {accuracy1:.2f}\")\n", | ||
" print(f\"Classification Accuracy catboost: {accuracy2:.2f}\")\n", | ||
" print(f\"Classification Accuracy lightgbm: {accuracy3:.2f}\")" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "GlNUpp9nb_cT", | ||
"outputId": "65d60559-4f75-4fa6-8a44-f76a277a804d" | ||
}, | ||
"execution_count": 2, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stderr", | ||
"text": [ | ||
"/usr/local/lib/python3.10/dist-packages/dask/dataframe/__init__.py:42: FutureWarning: \n", | ||
"Dask dataframe query planning is disabled because dask-expr is not installed.\n", | ||
"\n", | ||
"You can install it with `pip install dask[dataframe]` or `conda install dask`.\n", | ||
"This will raise in a future version.\n", | ||
"\n", | ||
" warnings.warn(msg, FutureWarning)\n" | ||
] | ||
}, | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"Classification Accuracy xgboost: 1.00\n", | ||
"Classification Accuracy catboost: 1.00\n", | ||
"Classification Accuracy lightgbm: 1.00\n", | ||
"Classification Accuracy xgboost: 0.96\n", | ||
"Classification Accuracy catboost: 0.97\n", | ||
"Classification Accuracy lightgbm: 0.96\n", | ||
"Classification Accuracy xgboost: 0.97\n", | ||
"Classification Accuracy catboost: 1.00\n", | ||
"Classification Accuracy lightgbm: 1.00\n" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"import numpy as np" | ||
], | ||
"metadata": { | ||
"id": "s1IzV5uJu9um" | ||
}, | ||
"execution_count": 3, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"import unifiedbooster as ub\n", | ||
"from sklearn.datasets import fetch_california_housing, load_diabetes\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"from sklearn.metrics import mean_squared_error\n", | ||
"\n", | ||
"\n", | ||
"datasets = [fetch_california_housing(), load_diabetes()]\n", | ||
"\n", | ||
"for dataset in datasets:\n", | ||
"\n", | ||
" # Load dataset\n", | ||
" X, y = dataset.data, dataset.target\n", | ||
"\n", | ||
" # Split dataset into training and testing sets\n", | ||
" X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n", | ||
"\n", | ||
" # Initialize the unified regressor (example with XGBoost)\n", | ||
" regressor1 = ub.GBDTRegressor(model_type='xgboost')\n", | ||
" regressor2 = ub.GBDTRegressor(model_type='catboost')\n", | ||
" regressor3 = ub.GBDTRegressor(model_type='lightgbm')\n", | ||
"\n", | ||
" # Fit the model\n", | ||
" regressor1.fit(X_train, y_train)\n", | ||
" regressor2.fit(X_train, y_train)\n", | ||
" regressor3.fit(X_train, y_train)\n", | ||
"\n", | ||
" # Predict on the test set\n", | ||
" y_pred1 = regressor1.predict(X_test)\n", | ||
" y_pred2 = regressor2.predict(X_test)\n", | ||
" y_pred3 = regressor3.predict(X_test)\n", | ||
"\n", | ||
" # Evaluate the model\n", | ||
" mse1 = np.sqrt(mean_squared_error(y_test, y_pred1))\n", | ||
" mse2 = np.sqrt(mean_squared_error(y_test, y_pred2))\n", | ||
" mse3 = np.sqrt(mean_squared_error(y_test, y_pred3))\n", | ||
" print(f\"Regression Root Mean Squared Error xgboost: {mse1:.2f}\")\n", | ||
" print(f\"Regression Root Mean Squared Error catboost: {mse2:.2f}\")\n", | ||
" print(f\"Regression Root Mean Squared Error lightgbm: {mse3:.2f}\")" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "u2vdE0mulk8q", | ||
"outputId": "6220d000-4662-4040-e1a5-f723bd721e2f" | ||
}, | ||
"execution_count": 4, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"Regression Root Mean Squared Error xgboost: 0.54\n", | ||
"Regression Root Mean Squared Error catboost: 0.58\n", | ||
"Regression Root Mean Squared Error lightgbm: 0.54\n", | ||
"Regression Root Mean Squared Error xgboost: 54.40\n", | ||
"Regression Root Mean Squared Error catboost: 51.72\n", | ||
"Regression Root Mean Squared Error lightgbm: 53.19\n" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |