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
- Load packages
from xgbexcel import XGBtoExcel
import numpy as np
from xgboost import XGBRegressor
- 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)
- Convert XGBRegressor model to an Excel formula
xgb_excel_expr = XGBtoExcel(model)
xgb_excel_expr.expression
- 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 theXGBRegressormodel andX_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
- Save Excel expression to a file
xgb_excel_expr.save_expr('dummy.txt')
- 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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xgbexcel-0.1.0.tar.gz | 4.8 kB | Without provenance | Details for xgbexcel-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xgbexcel-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for xgbexcel-0.1.0-py3-none-any.whl |
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
|
Security for xgbexcel 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.