Decision Tree Model | BYOM | Teradata Vantage - Decision Tree Model - Teradata Vantage

Teradata Vantage™ - Bring Your Own Model User Guide

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Lake
Product
Teradata Vantage
Release Number
20.00
Publication Date
May 2026
Content Type
User Guide
Publication ID
B700-1111-051K
ft:locale
en-US
ft:lastEdition
2026-06-18
dita:mapPath
fee1607120608274.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
ft:sourceId
dita
dita:id
fee1607120608274

This Python pipeline creates a PMML Decision Tree model. Scikit-learn APIs fetch the data from Teradata Vantage. Therefore, this pipeline must specify the connection, predictors, and variables.

"""
iris_db_dt_model.py: Creates Decision Tree model
********************
*  Generated model file is in PMML format.
*  To score this model , user needs insert/upload PMML model into Vantage table
********************
"""
from sklearn import datasets, tree
import pandas as pd

from sklearn2pmml.pipeline import PMMLPipeline
from sklearn2pmml import sklearn2pmml

import os
import time
from teradataml import *

display.print_sqlmr_query = True
passwd = "alice"
uid = "alice"

con = create_context(host="server123@mydomain.com", username=uid, password=passwd)
con

train_df = DataFrame.from_query("select * from iris_train")
traid_pd = train_df.to_pandas()
traid_pd
type(traid_pd)

X = traid_pd[['sepal_length','sepal_width','petal_length', 'petal_width' ]]
y=traid_pd[['species']]
X
pipeline = PMMLPipeline([
    ("classifier", tree.DecisionTreeClassifier())
])

pipeline.fit(X, y.values.ravel())

sklearn2pmml(pipeline, "iris_db_dt_model.pmml", with_repr = True)