Hyperparameter Tuning Operations on Non-Model Trainer Function | RandomSearch - Example 3: Hyperparameter Tuning Operations on Non-Model Trainer Function - Teradata Package for Python

Teradata® Package for Python User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
December 2024
ft:locale
en-US
ft:lastEdition
2025-01-23
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
lifecycle
latest
Product Category
Teradata Vantage

teradataml offers hyper-parameterization of parameters for non-model trainer functions using RandomSearch algorithm. This example makes use of hyper-parameterization feature to perform Antiselect function on titanic data.

In this example, teradataml example titanic data is used to perform Antiselect function.

  1. Example setup.
    1. Load the example dataset.
      >>> load_example_data("teradataml", "titanic")
    2. Create teradataml DataFrame.
      >>> titanic = DataFrame.from_table("titanic")
    3. Slice input data for Hyper-parameterization of data.
      >>> train_df1 = titanic.iloc[:200]
      >>> train_df2 = titanic.iloc[200:]
  2. Define hyperparameter-tuning for Antiselect (non-model trainer function).
    1. Define the non-model trainer function parameter space. Include input data in parameter space for non-model trainer function.
      >>> params = {"data":(train_df1, train_df2), "exclude":(
                    ['survived', 'name', 'age'],
                    ['survived', 'age'],
                    ["ticket", "parch", "age"],
                    ["ticket", "parch", "sex", "age"])}
      Any argument in 'params' can be hyper-parameterized.
    2. Import non-model trainer function and optimizer.
      >>> from teradataml import Antiselect, RandomSearch
    3. Initialize the RandomSearch optimizer with non-model trainer function and parameter space required for non-model training.
      >>> rs_obj = RandomSearch(func=Antiselect, params=params, n_iter=3)
  3. Perform execution of Antiselect function and execute parallel run in the background.
    1. Perform execution of Antiselect function in background.
      >>> rs_obj.fit(wait=False)
      Best model selection is not supported by hyperparameter tuning for non-model trainer function.
    2. Check hyperparameter tuning execution status.
      >>> rs_obj.is_running()
      True
    3. Check execution status after some interval.
      >>> rs_obj.is_running()
      False
      is_running() method works for both sequential and parallel execution.
  4. View the non-model trainer function execution metadata. Retrieve the model metadata of "rs_obj" instance.
    >>> rs_obj.models
           MODEL_ID                                         PARAMETERS STATUS
    0  ANTISELECT_0  {'data': '"ALICE"."ml__select__169839553065344...   PASS
    1  ANTISELECT_1  {'data': '"ALICE"."ml__select__169839553065344...   PASS
    2  ANTISELECT_2     {'data': None, 'exclude': ['survived', 'age']}   PASS
    All model training has been passed. In case of failure, use get_error_log method to retrieve corresponding error logs.
  5. Retrieve the parameter grid for non-model trainer function. Retrieve "rs_obj" object's parameter grid.
    >>> rs_obj.get_parameter_grid()
    [{'data': '"ALICE"."ml__select__169839553065344"',
      'exclude': ['ticket', 'parch', 'sex', 'age']},
     {'data': '"ALICE"."ml__select__169839553065344"',
      'exclude': ['ticket', 'parch', 'age']},
     {'data': None, 'exclude': ['survived', 'age']}]
  6. Get the non-model function execution result from RandomSearch instance "ANTISELECT_2".
    >>> rs_obj.get_model("ANTISELECT_2")
    ############ result Output ############
    
       passenger  pclass                                                 name     sex  sibsp  parch            ticket     fare cabin embarked
    0          3       3                               Heikkinen, Miss. Laina  female      0      0  STON/O2. 3101282   7.9250  None        S
    1          5       3                             Allen, Mr. William Henry    male      0      0            373450   8.0500  None        S
    2          6       3                                     Moran, Mr. James    male      0      0            330877   8.4583  None        Q
    3          7       1                              McCarthy, Mr. Timothy J    male      0      0             17463  51.8625   E46        S
    4          9       3    Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)  female      0      2            347742  11.1333  None        S
    5         10       2                  Nasser, Mrs. Nicholas (Adele Achem)  female      1      0            237736  30.0708  None        C
    6          8       3                       Palsson, Master. Gosta Leonard    male      3      1            349909  21.0750  None        S
    7          4       1         Futrelle, Mrs. Jacques Heath (Lily May Peel)  female      1      0            113803  53.1000  C123        S
    8          2       1  Cumings, Mrs. John Bradley (Florence Briggs Thayer)  female      1      0          PC 17599  71.2833   C85        C
    9          1       3                              Braund, Mr. Owen Harris    male      1      0         A/5 21171   7.2500  None        S