Skip to main content

Module for converting sklearn model to Teradata Vantage model

Project description

sklearn2vantage is a Python module for converting sklearn model to Teradata Vantage model table.

This module has 2 feature. One is converting scikit-learn model to Teradata Vantage model and another is uploading pandas dataframe to Teradata.



sklearn2vantage requires:

  • Python
  • NumPy
  • pandas
  • SQLAlchemy
  • scikit-learn
  • paramiko
  • scp
  • teradata
  • sqlalchemy-teradata
  • teradatasql
  • teradatasqlalchemy

Supported model

Following models are supported.

scikit-learn Teradata Vantage
RandomForestClassifier DecisionForestPredict
RandomForestRegressor DecisionForestPredict
GradientBoostRegressor DecisionForestPredict
LinearRegression GLMPredict
Lasso GLMPredict
Ridge GLMPredict
Linear GLMPredict
LogisticRegression GLMPredict
GaussianNB NaiveBayesPredict
CategoricalNB NaiveBayesPredict
DecisionTreeClassifier DecisionTreePredict
DecusionTreeRegressor DecisionTreePredict

Some models in statsmodels are also supported.

statsmodels Teradata Vantage
Logit GLMPredict
OLS GLMPredict

User installation

pip install sklearn2vantage


conda install sklearn2vantage -c temporary-recipes

Example: conveting model

import sklearn2vantage as s2v
import pandas as pd
from sqlalchemy import create_engine
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier

engine = create_engine("teradata://dbc:dbc@")

df = pd.read_sql_query("select * from some_data sample 50000", engine)
X = df.drop("target", axis=1)
y =
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)

rf_clf = RandomForestClassifier(), y_train)

rf_clf_table = \
  s2v.make_model_table_forest(rf_clf, X_train.columns,
                              ['setosa', 'versicolor', 'virginica'])

s2v.load_model_forest(rf_clf_table, engine, "rf_clf_table")
  select * from DecisionForestPredict (
    on iris partition by any
    on rf_clf_table as ModelTable DIMENSION
    NumerixInputs ('sepal_length', 'sepal_width',
                  'petal_length', 'petal_width')
    IdColumn ('id')
    Accumulate ('species')
    Detailed ('false')
) as dt""", engine)

For further usage, please see HowToUse.ipynb.

Example: data loading

import pandas as pd
import sklearn2vantage as s2v
from sqlalchemy import create_engine
engine = create_engine("teradata://dbc:dbc@")
df_titanic = pd.read_csv("titanic/train.csv").set_index("PassengerId")
s2v.tdload_df(df_titanic, engine, tablename="titanic_train",
              ifExists="replace", ssh_ip="",
              ssh_username="root", ssh_password="root")

For further usage, please see HowToUseDataloader.ipynb.

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

sklearn2vantage-0.1.9.tar.gz (10.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page