Converts SKlearn python model objects into SQL query snippets.
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
Install the package
pip install skql
Import skql package
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 )
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 )
Created and manageed by: Aditya Kumar email@example.com https://www.linkedin.com/in/nullp0inter/
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.