Convert tree-based ML models to SQL queries
Project description
sqlgbm
sqlgbm is a Python library that converts tree-based machine learning models into SQL queries. This allows you to deploy your ML models directly in your database without any additional infrastructure.
Installation
pip install sqlgbm
Usage
sqlgbm currently supports LightGBM models and can convert them to SQL queries:
from sqlgbm import SQLGBM
import lightgbm as lgb
import pandas as pd
# Load titanic dataset
titanic = pd.read_csv('titanic.csv')
features = ['pclass', 'sex', 'age', 'fare']
X = titanic[features]
X['sex'] = X['sex'].astype('category')
y = titanic['survived']
# Train model
clf = lgb.LGBMClassifier(n_estimators=3, max_depth=3)
clf.fit(X, y, categorical_feature=['sex'])
# Convert to SQL
sqlgbm = SQLGBM(clf, cat_features=['sex'])
sql = sqlgbm.generate_query('titanic', 'probability')
print(sql)
Output Types
sqlgbm supports different output formats:
raw: Returns the raw model outputprobability: Returns the probability (after sigmoid transformation)prediction: Returns the binary prediction (0 or 1) based on a 0.5 thresholdall: Returns all three outputs
License
MIT
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
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 sqlgbm-0.1.0.tar.gz.
File metadata
- Download URL: sqlgbm-0.1.0.tar.gz
- Upload date:
- Size: 27.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b68cf19edc0a0af4086de3229f4f1c343702e8d3557a2a36340553f1c3a4f381
|
|
| MD5 |
8fddf9ab96f34180f5f2ef4231cb30f1
|
|
| BLAKE2b-256 |
c17cfd96f2e3f9796e681ca3f5fdf10debfa5516242186970609a3943aebb152
|
File details
Details for the file sqlgbm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sqlgbm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2add908e5229ac9e9496b43d3365fa7c2734ae08807af9b1412d98ffb9d63cc9
|
|
| MD5 |
35a3b13a93fbb2eeaac2ff3f3acd510f
|
|
| BLAKE2b-256 |
a8194059640b441450a11d1b97e8c19ba73f94a14f1af53132d677499e4812ed
|