TD_GLMPredict Examples | GLMPredict | Teradata Vantage - Examples: How to Use TD_GLMPredict - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

Example: TD_GLMPredict Using Credit Data

This example takes credit data and uses TD_GLM function to get a model. You can view the input and output in the TD_GLM example.

TD_GLMPredict Call for Credit Data

CREATE VOLATILE TABLE vt_glm_predict_credit_ex AS (
    SELECT * from TD_GLMPredict (
      ON credit_ex_merged AS INPUTTABLE
      ON td_glm_output_credit_ex AS Model DIMENSION
      USING
      IDColumn ('ID')
      Accumulate('Outcome')
    ) AS dt
) WITH DATA
ON COMMIT PRESERVE ROWS;

TD_GLMPredict Output for Credit Data

ID Prediction Outcome
61 1 1
297 0 0
631 0 0
122 1 1
... ... ...

Example: TD_GLMPredict Using Housing Data

This example takes raw housing data, and does the following:
  1. Uses TD_ScaleFit to standardize the data.
  2. Uses TD_ScaleTransform to transform the data.
  3. Uses TD_GLM to get a model.
  4. Uses TD_GLMPredict to predict target values.

You can view the input and output of steps 1 through 3 in the TD_GLM example.

TD_GLMPredict Call for Housing Data

CREATE VOLATILE TABLE vt_predict_cal_ex AS (
    SELECT * from TD_GLMPredict (
      ON cal_housing_ex_scaled AS INPUTTABLE
      ON td_glm_cal_ex AS Model DIMENSION
      USING
      IDColumn ('ID')
      Accumulate('MedHouseVal')
    ) AS dt
) WITH DATA
ON COMMIT PRESERVE ROWS;

TD_GLMPredict Output for Housing Data

ID Prediction MedHouseVal
2833 1.5762 0.6
5328 2.29801 2.775
5300 1.82705 3.5
12433 0.863867 0.664
... ... ...

TD_GLMPredict Call with Family: Gaussian

SELECT * FROM TD_GLMPredict (
  ON housing_train_segment AS InputTable PARTITION BY partition_id
  ON (SELECT * FROM TD_GLM (
     ON housing_train_segment AS InputTable PARTITION BY partition_id ORDER BY sn
     USING
     Family('Gaussian')
     InputColumns('[3:10]')
     ResponseColumn('price')
     BatchSize(10)
     MaxIterNum (1000)
     ) AS output_glmsegment_gaussian) AS ModelTable PARTITION BY partition_id
  USING
  IDColumn ('sn')
  Accumulate('price')
) AS dt ORDER BY 1, 2;

TD_GLMPredict Output with Family: Gaussian

partition_id sn prediction homestyle error_code
31 1 62435.02250123067 0 -
31 2 42488.026553751566 0 -
31 3 51292.39820831003 0 -
31 4 60973.66568546524 1 -
... ... ... ... -

TD_GLMPredict Call with Family: Binomial

SELECT * from TD_GLMPredict (
  ON housing_train_segment AS InputTable PARTITION BY partition_id
  ON (select * from TD_GLM (
    ON housing_train_segment AS InputTable partition by partition_id
    USING
    Family('Binomial')
    InputColumns('[3:10]')
    ResponseColumn('homestyle')
    MaxIterNum (100)
    ) as glm_output) AS ModelTable PARTITION BY partition_id
  USING
  IDColumn ('sn')
  OutputProb('true')
  Responses('0','1')
  Accumulate('homestyle')
) AS dt order by 1, 2;

TD_GLMPredict Output with Family: Binomial

partition_id sn prediction prob_0 prob_1 homestyle error_code
31 1 0 0.9484787 0.0515213 0  
31 2 0 0.92724316 0.07275684 0  
31 3 0 0.92724316 0.07275684 0  
31 4 0 0.97812107 0.02187893 1  
31 5 0 0.92724316 0.07275684 1  
... ... ... ... ... ... ...