Now that our dataset is ready with scaled and encoded features, let's split it into training and testing datasets. We will use 75% of the data for training and 25% for testing.
Teradata In-Database Analytic Functions provide the TD_TrainTestSplit function, which we will use to split our dataset.
-- Create a train/test split on the input table
CREATE VIEW td_analytics_functions_demo.train_test_split AS (
SELECT * FROM TD_TrainTestSplit(
ON td_analytics_functions_demo.feature_enriched_accounts_consolidated AS InputTable
USING
IDColumn('cust_id')
TrainSize(0.75)
TestSize(0.25)
Seed(42)
) AS dt
);
As shown below, the function adds a new column, TD_IsTrainRow, where 1 indicates a training row and 0 indicates a testing row.
We will use TD_IsTrainRow to create two tables: one for training and one for testing.
-- Create the training table
CREATE TABLE td_analytics_functions_demo.training_table AS (
SELECT *
FROM td_analytics_functions_demo.train_test_split
WHERE TD_IsTrainRow = 1
) WITH DATA;
-- Create the testing table
CREATE TABLE td_analytics_functions_demo.testing_table AS (
SELECT *
FROM td_analytics_functions_demo.train_test_split
WHERE TD_IsTrainRow = 0
) WITH DATA;