Convert an XGBRegressor model to an Excel formula expression.
Project description
xgbexcel
Python package that converts an XGBRegressor model to an Excel formula expression.
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 theXGBRegressor
model 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.0.1.tar.gz
(3.8 kB
view details)
Built Distribution
File details
Details for the file xgbexcel-0.0.1.tar.gz
.
File metadata
- Download URL: xgbexcel-0.0.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be9e722a7eadbb2f52b6de209e79e8d107ce3d7533e787d8e2caa31c270029ed |
|
MD5 | 047328be40b0b45209d5a2f3c1894000 |
|
BLAKE2b-256 | 26e6fb533ab846cac6b6ce8def24cbece52691a65c4a728ed6e844b2188d606a |
File details
Details for the file xgbexcel-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: xgbexcel-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e340023968b1594414e395579ae0fd09d0c321d9c2952935bcce2f150b6c06b9 |
|
MD5 | 51cf7381d757e54428c2243e0123aa77 |
|
BLAKE2b-256 | 1c089a5ae42fae367363008bf8e8ba3079214be9da97c2e619c0a57c2adc70c3 |