Skip to main content

Convert XGBRegressor or XGBClassifier models to an Excel formula expression.

Project description

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

Project details


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xgbexcel-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

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

Hashes for xgbexcel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 139ec0f9604be61a285a1b5358d178bbf4f7de6599366a4018a1686ef9627be1
MD5 60722488a6b24abc9d246398d43942f3
BLAKE2b-256 e0babc8063c0a9cc303800c19ad9c963d52e93a0ee0b08ccf9375a5efeee468e

See more details on using hashes here.

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

Hashes for xgbexcel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 073f64b561331d6c5cad6e3fad6619a99d3b0323948dcfb6bc38fbce4ab3a326
MD5 1ad2cc61025b7347824f4ce0dbee91f2
BLAKE2b-256 c18e71740562b09854eb6396306f3f744e2f73c2c2f2c9b84d00d65e3031f82d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page