Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XGboost sponsorhip notebook with datapanel #175

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://cdn.comet.ml/img/notebook_logo.png\"> <img height=90px align=\"right\" src=\"https://camo.githubusercontent.com/0f091e4259df42e93eb9658f8fc224c8075d01ffc7a4bed16a78b06524e4b4a6/68747470733a2f2f7867626f6f73742e61692f696d616765732f6c6f676f2f7867626f6f73742d6c6f676f2e737667\">\n",
"\n",
"[Comet](https://www.comet.com/?utm_source=xgboost&utm_medium=colab&utm_content=intro_cell) helps Data Scientists track, compare, debug, and visualize their model training runs. Many ML teams leverage Comet as their single system of record of model's performance in both training anf production \n",
"This notebook shows you how to log your XGBoost Training Runs with Comet with just a additional lines of code\n",
"\n",
"For more information about Comet's integration with XGBoost visit our [Docs](https://www.comet.com/docs/v2/integrations/ml-frameworks/xgboost/?utm_source=xgboost&utm_medium=colab&utm_content=intro_cell) page."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 🚧 Install Required Packages "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install xgboost comet_ml --quiet"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 🧪 Initialize Comet\n",
"\n",
"Create your free account at [Comet.com](https://www.comet.com/signup?utm_source=xgboost&utm_medium=colab&utm_content=signup_cell) and grab your API key which can be found under account settings."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import comet_ml\n",
"\n",
"comet_ml.init(project_name=\"comet-xgboost-tutorial\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 👁️ Train A Classification Model on the Iris Dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"from xgboost import XGBClassifier\n",
"# read data\n",
"from sklearn.datasets import load_iris\n",
"from sklearn.model_selection import train_test_split\n",
"\n",
"experiment = comet_ml.Experiment()\n",
"\n",
"data = load_iris(as_frame=True)\n",
"X_train, X_test, y_train, y_test = train_test_split(data['data'], data['target'], test_size=.2)\n",
"# create model instance\n",
"bst = XGBClassifier(n_estimators=10, max_depth=5, learning_rate=0.1, objective='binary:logistic')\n",
"# fit model\n",
"bst.fit(X_train, y_train, eval_set=[(X_test, y_test)],\n",
" eval_metric=\"merror\",)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 📊 View the Results in Comet \n",
"\n",
"Comet auto-logs the hyper-parameters, model graph, and metrics for a XGBoost training run"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"experiment.display(\"charts\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 📙 Log a prediction table to Comet "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# make predictions\n",
"y_pred = bst.predict(X_test)\n",
"\n",
"print(type(X_test))\n",
"\n",
"debug_df = X_test.copy()\n",
"\n",
"debug_df['pred'] = y_pred\n",
"debug_df['ground_truth'] = y_test\n",
"\n",
"experiment.log_table('prediction_debug_table.csv', debug_df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 🖥️ Debug Model Predictions with Comet's Data Panel\n",
"\n",
"![Gif](xg_data_panel.gif)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.11.0 ('nb': venv)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "8c9587381b2341d562742e36a89690be32a732b11830813473890249dd40a07d"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading
Loading