Code Monkey home page Code Monkey logo

sklearn2vantage's Introduction

sklearn2vantage

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.

Installation

Dependencies

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

or :

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:[email protected]:1025/tdwork")

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

rf_clf = RandomForestClassifier()
rf_clf.fit(X_train, 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")
pd.read_sql_query("""
  select * from DecisionForestPredict (
    on iris partition by any
    on rf_clf_table as ModelTable DIMENSION
    USING
    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:[email protected]:1025/tdwork")
df_titanic = pd.read_csv("titanic/train.csv").set_index("PassengerId")
s2v.tdload_df(df_titanic, engine, tablename="titanic_train",
              ifExists="replace", ssh_ip="173.168.56.128",
              ssh_username="root", ssh_password="root")

For further usage, please see HowToUseDataloader.ipynb.

sklearn2vantage's People

Contributors

yukimura66 avatar mura5726 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.