We will now use the TD_GLM In-Database Analytic Function to train our model on the training dataset. The TD_GLM function is a generalized linear model (GLM) that performs regression and classification analysis on datasets.
In this example, we use input columns such as tot_income, ck_avg_bal, cc_avg_tran_amt, and one-hot encoded values for marital status, gender, and state. The dependent, or response, column is cc_avg_bal. Since cc_avg_bal is a continuous value, this is a regression problem. We use Family as Gaussian for regression and Binomial for classification.
The Tolerance parameter specifies the minimum improvement required in prediction accuracy for the model to continue iterating, while MaxIterNum specifies the maximum number of iterations allowed. Training stops when either condition is met first. In the example below, the model reaches CONVERGED status after 58 iterations.
-- Train the GLM model using the training dataset
CREATE TABLE td_analytics_functions_demo.GLM_model_training AS (
SELECT * FROM TD_GLM(
ON td_analytics_functions_demo.training_table AS InputTable
USING
InputColumns('tot_income', 'ck_avg_bal', 'cc_avg_tran_amt', '[19:26]')
ResponseColumn('cc_avg_bal')
Family('Gaussian')
MaxIterNum(300)
Tolerance(0.001)
Intercept('true')
) AS dt
) WITH DATA;