TD_OrdinalEncodingTransform Function Example | Teradata Vantage - Example: How to Use TD_OrdinalEncodingTransform - Analytics Database

Database Analytic Functions

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-10-04
dita:mapPath
gjn1627595495337.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
jmh1512506877710
Product Category
Teradata Vantageā„¢

TD_OrdinalEncodingFit InputTable: OrdEnc_titanic_train

passenger survived pclass name gender age sibsp parch ticket fare cabin embarked
873 0 1 Carlsson; Mr. Frans Olof male 33 0 0 695 5.0000 B51 B53 B55 S
631 1 1 Barksworth; Mr. Algernon Henry Wilson male 80 0 0 27042 30.0000 A23 S
97 0 1 Goldschmidt; Mr. George B male 71 0 0 PC 17754 34.6542 A5 C
1000 0 1     71 0 0   34.6542    
488 0 1 Kent; Mr. Edward Austin male 58 0 0 11771 29.7000 B37 C
505 1 1 Maioni; Miss. Roberta female 16 0 0 110152 86.5000 B79 S

Example: TD_OrdinalEncodingFit SQL Call Using Auto Approach

SELECT * FROM TD_OrdinalEncodingFit (
 ON ordinal_titanic_dataset AS InputTable
 OUT PERMANENT TABLE OutputTable (ordinal_titanic_fit_output)
 USING
 TargetColumn('name','gender','ticket','cabin','embarked')
 Approach ('AUTO')
 StartValue (5, 10, 15, 0, -5)
 DefaultValue (-1, -10, -15, 20, 0)
) AS dt ORDER BY 1,3;
Multiple column support for TD_OrdinalEncoding, TD_OneHotEncoding, and TD_Histogram is available in release 17.20.03.07 and later. If you are using an older version, the TargetColumn argument accepts only one column.

TD_OrdinalEncodingTransform Output Table Using Auto Approach

TD_ColumnName_ORDFIT TD_Category_ORDFIT TD_Value_ORDFIT TD_Index_ORDFIT name gender ticket cabin embarked
cabin   0 3 None None None None None
cabin A23 1 3 None None None None None
cabin A5 2 3 None None None None None
cabin B37 3 3 None None None None None
cabin B51 B53 B55 4 3 None None None None None
cabin B79 5 3 None None None None None
cabin TD_CATEGORY_COUNT 6 -1 None None None None None
cabin TD_OTHER_CATEGORY 20 -2 None None None None None
embarked   -5 4 None None None None None
embarked C -4 4 None None None None None
embarked S -3 4 None None None None None
embarked TD_OTHER_CATEGORY 0 -2 None None None None None
embarked TD_CATEGORY_COUNT 3 -1 None None None None None
name TD_OTHER_CATEGORY -1 -2 None None None None None
name   5 0 None None None None None
name Barksworth; Mr. Algernon Henry Wilson 6 0 None None None None None
name TD_CATEGORY_COUNT 6 -1 None None None None None
name Carlsson; Mr. Frans Olof 7 0 None None None None None
name Goldschmidt; Mr. George B 8 0 None None None None None
name Kent; Mr. Edward Austin 9 0 None None None None None
name Maioni; Miss. Roberta 10 0 None None None None None
gender TD_OTHER_CATEGORY -10 -2 None None None None None
gender TD_CATEGORY_COUNT 3 -1 None None None None None
gender   10 1 None None None None None
gender female 11 1 None None None None None
gender male 12 1 None None None None None
ticket TD_OTHER_CATEGORY -15 -2 None None None None None
ticket TD_CATEGORY_COUNT 6 -1 None None None None None
ticket   15 2 None None None None None
ticket 110152 16 2 None None None None None
ticket 11771 17 2 None None None None None
ticket 27042 18 2 None None None None None
ticket 695 19 2 None None None None None
ticket PC 17754 20 2 None None None None None

Example: TD_OrdinalEncodingTransform SQL Call Using Output from TD_OrdinalEncodingFit

SELECT * FROM TD_OrdinalEncodingTransform (
 ON ordinal_titanic_dataset AS InputTable
 ON ordinal_titanic_fit_output as FitTable Dimension
  USING
 Accumulate ('passenger')
) AS dt ORDER BY 1;

TD_OrdinalEncodingTransform Output

 passenger name gender ticket cabin embarked
 --------- ---- ------ ------ ----- --------
        97    8     12     20     2       -4
       488    9     12     17     3       -4
       505   10     11     16     5       -3
       631    6     12     18     1       -3
       873    7     12     19     4       -3
      1000    5     10     15     0       -5