Convert XGBRegressor or XGBClassifier models to an Excel formula expression.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xgbexcel-0.1.0.tar.gz
(4.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xgbexcel-0.1.0.tar.gz.
File metadata
- Download URL: xgbexcel-0.1.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
139ec0f9604be61a285a1b5358d178bbf4f7de6599366a4018a1686ef9627be1
|
|
| MD5 |
60722488a6b24abc9d246398d43942f3
|
|
| BLAKE2b-256 |
e0babc8063c0a9cc303800c19ad9c963d52e93a0ee0b08ccf9375a5efeee468e
|
File details
Details for the file xgbexcel-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xgbexcel-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
073f64b561331d6c5cad6e3fad6619a99d3b0323948dcfb6bc38fbce4ab3a326
|
|
| MD5 |
1ad2cc61025b7347824f4ce0dbee91f2
|
|
| BLAKE2b-256 |
c18e71740562b09854eb6396306f3f744e2f73c2c2f2c9b84d00d65e3031f82d
|