====
skql
====

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.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
