Skip to main content

Downloads Python package contributions welcome

xgbexcel

Python package that converts an XGBRegressor model to an Excel formula expression.

NB: The package works with xgboost==1.7.1. In xgboost==2.0, vector leaves were introduced. While I may have limited time to address this myself, contributions and improvements are always welcome. Start from here

How to start

First, you have to install the package.

pip install xgbexcel

How to convert XGBRegressor model to an Excel formula

  1. Load packages
from xgbexcel import XGBtoExcel
import numpy as np
from xgboost import XGBRegressor
  1. Create dummy dataset and fit XGBRegressor model
X_train, y_train = np.random.randint(0, 1000, (100, 2)), np.random.randint(0, 10, 100)
model = XGBRegressor(n_estimators=2, max_depth=1)
model.fit(X_train, y_train)
  1. Convert XGBRegressor model to an Excel formula
xgb_excel_expr = XGBtoExcel(model)
xgb_excel_expr.expression
  1. The features in the Excel formula are represented using the x1, x2, x3, etc. notation, where the numbers correspond to the enumeration of the features in the XGBRegressor model and X_train. You can manually rename the features in the Excel formula to match the desired column names in the Excel sheet. Once you have renamed the features, you can copy the expression in the Excel sheet as a formula.
feature_map = {'x1': 'feature1', 'x2': 'feature2'}
xgb_excel_expr.rename_features(feature_map)
xgb_excel_expr.expression
  1. Save Excel expression to a file
xgb_excel_expr.save_expr('dummy.txt')
  1. Enjoy

Try it yourself in the example notebook: howXGBtoExcel.ipynb

Metadata

Release files for xgbexcel 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xgbexcel 0.1.0
File Size Uploaded
xgbexcel-0.1.0.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xgbexcel 0.1.0
File Interpreter ABI Platform
xgbexcel-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / xgbexcel-0.1.0.tar.gz

Download URL xgbexcel-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
139ec0f9604be61a285a1b5358d178bbf4f7de6599366a4018a1686ef9627be1
BLAKE2b-256 checksum
How to use checksums
e0babc8063c0a9cc303800c19ad9c963d52e93a0ee0b08ccf9375a5efeee468e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.18

Release files / xgbexcel-0.1.0-py3-none-any.whl

Download URL xgbexcel-0.1.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
073f64b561331d6c5cad6e3fad6619a99d3b0323948dcfb6bc38fbce4ab3a326
BLAKE2b-256 checksum
How to use checksums
c18e71740562b09854eb6396306f3f744e2f73c2c2f2c9b84d00d65e3031f82d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page