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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

Supported by

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