Example: Deploy and Load Model Trained outside Vantage | teradataml OpenSourceML - Example: Deploy and Load Model Trained outside Vantage - Teradata Package for Python

Teradata® Package for Python User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
March 2024
Language
English (United States)
Last Update
2024-04-09
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
Product Category
Teradata Vantage
  1. Train scikit-learn model.
    >>> import numpy as np
    >>> from sklearn.pipeline import make_pipeline
    >>> from sklearn.preprocessing import StandardScaler
    >>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
    >>> y = np.array([1, 1, 2, 2])
    >>> from sklearn.svm import SVC
    >>> clf = make_pipeline(StandardScaler(), SVC(gamma='auto'))
    >>> clf.fit(X, y)
    Pipeline(steps=[('standardscaler', StandardScaler()),
                    ('svc', SVC(gamma='auto'))])
  2. Deploy model trained outside Vantage.
    # Import the module.
    >>> from teradataml import td_sklearn as osml
    >>> svc_obj = osml.deploy(model_name="svc_outside_tdml", model=clf, replace_if_exists=True)
    Model is deleted.
    Model is saved.
  3. Load the model that is deployed from outside Vantage.
    >>> loaded2 = osml.load(model_name="svc_outside_tdml")
    >>> loaded2
    Pipeline(steps=[('standardscaler', StandardScaler()),
                    ('svc', SVC(gamma='auto'))])
  4. Predict on loaded model.
    >>> loaded2.predict(df_x_clasif.select(["col1", "col2"]))
                 col1                 col2    pipeline_predict_1
    0.426749100345748    0.052892805973648                     2
    0.061358610926176    -0.32391973812397                     1
     1.06516942678559     1.37093616727654                     2
     1.34487963860504    0.006631689510300                     2
     1.13904878664119     1.05078416796634                     2
    0.615820493677217    0.351753443920848                     2
    -0.58236154328365    -0.95815122115123                     1
     1.36289521790798    0.273506135473117                     2
    -1.24268158066154    -1.14715279214675                     1
    0.790100366929475    0.685306235288764                     2