Teradata Package for R Function Reference | 17.20 - TrainTestSplit - Teradata Package for R - Look here for syntax, methods and examples for the functions included in the Teradata Package for R.

Teradata® Package for R Function Reference

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for R
Release Number
17.20
Published
March 2024
Language
English (United States)
Last Update
2024-05-03
dita:id
TeradataR_FxRef_Enterprise_1720
Product Category
Teradata Vantage

TrainTestSplit

Description

The td_train_test_split_sqle() function simulates how a model would perform on new data. The function divides the dataset into train and test subsets to evaluate machine learning algorithms and validate processes. The first subset is used to train the model. The second subset is used to make predictions and compare the predictions to actual values.

Notes:

  • The td_train_test_split_sqle() function gives consistent results across multiple runs on same machine. With different machines, it might produce different train and test datasets.

  • Requires the UTF8 client character set for UNICODE data.

  • Does not support Pass Through Characters (PTCs).

  • Does not support KanjiSJIS or graphic data types.

Usage

  td_train_test_split_sqle (
      data = NULL,
      id.column = NULL,
      stratify.column = NULL,
      seed = NULL,
      train.size = 0.75,
      test.size = 0.25,
      ...
  )

Arguments

data

Required Argument.
Specifies the input tbl_teradata on which split to be performed.
Types: tbl_teradata

id.column

Optional Argument.
Specifies the input data column name that has the
unique identifier for each row in the input.
Notes:

  • Mandatory when "seed" argument is present so that the output of td_train_test_split_sqle() function is deterministic across multiple function calls.

Types: character

stratify.column

Optional Argument.
Specifies column name that contains the labels indicating which data needs to be stratified.
Types: character

seed

Optional Argument.
Specifies the seed value that controls the shuffling applied to the data before applying the split. Pass an integer for reproducible output across multiple function calls.
Notes:

  • When the argument is not specified, different runs of the query generate different outputs.

  • It must be in the range [0, 2147483647]

Types: integer

train.size

Optional Argument.
Specifies the size of the train dataset.
Notes:

  • If both "train.size" and "test.size" arguments are specified, then their sum must be equal to 1.

  • "train.size" and "test.size" should be greater than the number of classes when using stratify.

  • If the input data does not have an identifier column, then td_fill_row_id_sqle() function can be used to generate one.

  • It must be in the range (0, 1)

Default Value: 0.75
Types: float

test.size

Optional Argument.
Specifies the size of the test dataset.
Note:

  • It must be in the range (0, 1)

Default Value: 0.25
Types: float

...

Specifies the generic keyword arguments SQLE functions accept. Below are the generic keyword arguments:

persist:
Optional Argument.
Specifies whether to persist the results of the function in a table or not. When set to TRUE, results are persisted in a table; otherwise, results are garbage collected at the end of the session.
Default Value: FALSE
Types: logical

volatile:
Optional Argument.
Specifies whether to put the results of the function in a volatile table or not. When set to TRUE, results are stored in a volatile table, otherwise not.
Default Value: FALSE
Types: logical

Function allows the user to partition, hash, order or local order the input data. These generic arguments are available for each argument that accepts tbl_teradata as input and can be accessed as:

  • "<input.data.arg.name>.partition.column" accepts character or vector of character (Strings)

  • "<input.data.arg.name>.hash.column" accepts character or vector of character (Strings)

  • "<input.data.arg.name>.order.column" accepts character or vector of character (Strings)

  • "local.order.<input.data.arg.name>" accepts logical

Note:
These generic arguments are supported by tdplyr if the underlying SQL Engine function supports, else an exception is raised.

Value

Function returns an object of class "td_train_test_split_sqle" which is a named list containing object of class "tbl_teradata".
Named list member(s) can be referenced directly with the "$" operator using the name(s):result

Examples

  
    
    # Get the current context/connection.
    con <- td_get_context()$connection

    # Load the example data.
    loadExampleData("tdplyr_example", "titanic")

    # Create tbl_teradata object.
    data_input <- tbl(con, "titanic")

    # Check the list of available analytic functions.
    display_analytic_functions()

    # Example 1 : Split the input data to test dataset and train dataset,
    #             with ratio of test:train is 20:80. Note that output
    #             of td_train_test_split_sqle() function contains 'TD_IsTrainRow'
    #             column in which '0' represent test data and '1'
    #             represent train data.
    TrainTestSplit_out <- td_train_test_split_sqle(
                            data = data_input,
                            id.column="passenger",
                            train.size=0.80,
                            test.size=0.20,
                            seed=42)

    # Print the result.
    print(TrainTestSplit_out$result)