Skip to main content

Converts SKlearn python model objects into SQL query snippets.

Project description

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.

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

skql-0.0.2.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

skql-0.0.2-py2.py3-none-any.whl (7.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file skql-0.0.2.tar.gz.

File metadata

  • Download URL: skql-0.0.2.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for skql-0.0.2.tar.gz
Algorithm Hash digest
SHA256 968d7c12f1c9701a9e4b75cb80454c5e39a310e7d0350c44ec00fd892d0f2799
MD5 3862fb99c267ec58513c84581d064347
BLAKE2b-256 112e63d413a08583a0e17c840b702330c28968f4a35f648a8b1b45f8e9bbaa4f

See more details on using hashes here.

File details

Details for the file skql-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: skql-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for skql-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b99f3a0ab78259e80ccf8c17503779373ee07f1dd3c475cd0e9b6701730c5895
MD5 1967655e0b547f5f482ad65244fc2ea6
BLAKE2b-256 23e6840fb57cf30ce1fd9671f2548068f05021a4c69c446682e2232b736db598

See more details on using hashes here.

Supported by

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