Skip to main content

Deploying a Machine Learning model is always a resource and cost intensive task.

This package converts a scikit-learn based machine learning models to SQL query, thereby allowing a model to be executed on a target data-set with the already existing SQL based database.

The current version is capable of conerting:
  • Decision Tree Classifier models

into a series of case when statements, where the resultant value could be the resultant class or the probability value associatd with a class.

Other model-type conversions will be released in subsequent versions.

  • Free software: MIT license

Usage

Install the package

pip install skql


Import skql package

import skql


Initialize the ‘DecisionTreeClassifierConverter’ instance with a valid scikit-learn DecisionTreeClassifier model object.

dtConverter = skql.DecisionTreeClassifierConverter( clf )

Classes of the tree are: [‘“Setosa”’ ‘“Versicolor”’ ‘“Virginica”’] Choose class index accordingly if probability values are required. :)

A message is displayed after initialization, as shown above. The message shows the classes, the model wa tarined with in a particular order. If a SQL query is to be generated that outputs the probability value for a particular class, the index of the class for which probability values are needed is slected from this list. starting from 0. For example of the SQL query to be generated need propabilty output for class “Versicolor”, the index to be entered is 1.


Get the list of columns that were used to train the data-set (without the target valriable)

used_columns = iris.drop([‘variety’], axis=1).columns

[‘sepal_length’, ‘sepal_width’, ‘petal_length’, ‘petal_width’]


If a SQL query is to be generated that classifies the dataset into respective classes.

sql = dtConverter.fit( cols = used_columns )

print(sql)


If a SQL query needs to be generated that gives probability values for class “Setosa”, given that that class order is [‘“Setosa”’ ‘“Versicolor”’ ‘“Virginica”’] as shown when initialsing the DecisionTreeClassifierConverter instance.

sql = dtConverter.fit( cols = used_columns, vbh_classes = False, class_index = 0 )

print(sql)


Credits

Created and manageed by: Aditya Kumar adityakumar3008@gmail.com https://www.linkedin.com/in/nullp0inter/

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Metadata

Release files for skql 0.0.2

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

Source distribution (sdist)

Source distribution for skql 0.0.2
File Size Uploaded
skql-0.0.2.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for skql 0.0.2
File Interpreter ABI Platform
skql-0.0.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 20.6 kB

Release files / skql-0.0.2.tar.gz

Download URL skql-0.0.2.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
968d7c12f1c9701a9e4b75cb80454c5e39a310e7d0350c44ec00fd892d0f2799
BLAKE2b-256 checksum
How to use checksums
112e63d413a08583a0e17c840b702330c28968f4a35f648a8b1b45f8e9bbaa4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3

Release files / skql-0.0.2-py2.py3-none-any.whl

Download URL skql-0.0.2-py2.py3-none-any.whl
Size 7.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b99f3a0ab78259e80ccf8c17503779373ee07f1dd3c475cd0e9b6701730c5895
BLAKE2b-256 checksum
How to use checksums
23e6840fb57cf30ce1fd9671f2548068f05021a4c69c446682e2232b736db598
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

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