Skip to main content

lgbm-to-code

This package provides functionality to convert trained LightGBM models into native code for different programming languages. This allows you to deploy your models in environments where Python or LightGBM dependencies might not be readily available.

Installation

pip install lgbm-to-code

Usage

import lightgbm as lgb
from lgbm_to_code import lgbm_to_code

# Train your LightGBM model...
# For example:
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split

diabetes = load_diabetes()
X = diabetes.data
y = diabetes.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = lgb.LGBMRegressor(random_state=42)
model.fit(X_train, y_train)

# Convert to desired language
languages = ["python", "cpp", "javascript"]
for language in languages:
    code = lgbm_to_code.parse_lgbm_model(model._Booster, language)
    with open(f"lgbm_model_{language}.{'py' if language == 'python' else language}", "w") as f:
        f.write(code)

Supported Languages

  • Python
  • C++
  • JavaScript

Example

import lightgbm as lgb
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split
from lgbm_to_code import lgbm_to_code

# Load dataset and train model
diabetes = load_diabetes()
X = diabetes.data
y = diabetes.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = lgb.LGBMRegressor(random_state=42)
model.fit(X_train, y_train)

# Generate Python code
python_code = lgbm_to_code.parse_lgbm_model(model._Booster, "python")

# Save the code to a file
with open("lgbm_model.py", "w") as f:
    f.write(python_code)

# Now you can use this code in a separate Python environment

Limitations

  • Currently, the code generation only supports numerical features.
  • The generated code is not optimized for performance.

License

MIT

Metadata

Release files for lgbm-to-code 0.2.1

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

Source distribution (sdist)

Source distribution for lgbm-to-code 0.2.1
File Size Uploaded Provenance
lgbm_to_code-0.2.1.tar.gz 4.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for lgbm-to-code 0.2.1
File Interpreter ABI Platform
lgbm_to_code-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / lgbm_to_code-0.2.1.tar.gz

Download URL lgbm_to_code-0.2.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7fa24a417c6d88416052a877bcce8fdb95538109f73cbf4e803a656abc3cba37
BLAKE2b-256 checksum
How to use checksums
3ac3ffb74f090459a2a1184904727a4c838f9fc6b3f3b2a3698bd2bdabcc2d95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.19

Release files / lgbm_to_code-0.2.1-py3-none-any.whl

Download URL lgbm_to_code-0.2.1-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb64308f783751675afa60dadfe3f37415ca6d56fa087c42be409e0dd6e6b0fc
BLAKE2b-256 checksum
How to use checksums
f0ad483a20ec805a727c52b1322d12b5dd1ee848f87abd4c9eba9141f7a9c027
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.19

Security for lgbm-to-code 0.2.1

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.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

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