Teradata Package for Python Function Reference | 20.00 - __init__ - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference - 20.00
- Deployment
- VantageCloud
- VantageCore
- Edition
- Enterprise
- IntelliFlex
- VMware
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.03
- Published
- December 2024
- ft:locale
- en-US
- ft:lastEdition
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- lifecycle
- latest
- Product Category
- Teradata Vantage
- teradataml.hyperparameter_tuner.optimizer.GridSearch.__init__ = __init__(self, func, params)
- DESCRIPTION:
GridSearch is an exhaustive search algorithm that covers all possible
parameter values to identify optimal hyperparameters. It works for
teradataml analytic functions from SQLE, BYOM, VAL and UAF features.
teradataml GridSearch allows user to perform hyperparameter tuning for
all model trainer and non-model trainer functions.
When used for model trainer functions:
* Based on evaluation metrics search determines best model.
* All methods and properties can be used.
When used for non-model trainer functions:
* Only fit() method is supported.
* User can choose the best output as they see fit to use this.
teradataml GridSearch also allows user to use input data as the
hyperparameter. This option can be suitable when the user wants to
identify the best models for a set of input data. When user passes
set of data as hyperparameter for model trainer function, the search
determines the best data along with the best model based on the
evaluation metrics.
PARAMETERS:
func:
Required Argument.
Specifies a teradataml analytic function from SQLE, VAL, and UAF.
Types:
teradataml Analytic Functions
* Advanced analytic functions
* UAF
* VAL
Refer to display_analytic_functions() function for list of functions.
params:
Required Argument.
Specifies the parameter(s) of a teradataml analytic function.
The parameter(s) must be in dictionary. keys refers to the
argument names and values refers to argument values for corresponding
arguments.
Notes:
* One can specify the argument value in a tuple to run HPT
with different arguments.
* Model trainer function arguments "id_column", "input_columns",
and "target_columns" must be passed in fit() method.
* All required arguments of non-model trainer function must
be passed while GridSearch object creation.
Types: dict
RETURNS:
None
RAISES:
TeradataMlException, TypeError, ValueError
EXAMPLES:
>>> # Example 1: Model trainer function. Performing hyperparameter-tuning
>>> # on SVM model trainer function.
>>> # Load the example data.
>>> load_example_data("teradataml", ["cal_housing_ex_raw"])
>>> # Create teradataml DataFrame objects.
>>> data_input = DataFrame.from_table("cal_housing_ex_raw")
>>> # Scale "target_columns" with respect to 'STD' value of the column.
>>> fit_obj = ScaleFit(data=data_input,
target_columns=['MedInc', 'HouseAge', 'AveRooms',
'AveBedrms', 'Population', 'AveOccup',
'Latitude', 'Longitude'],
scale_method="STD")
>>> # Transform the data.
>>> transform_obj = ScaleTransform(data=data_input,
object=fit_obj.output,
accumulate=["id", "MedHouseVal"])
>>> # Define parameter space for model training.
>>> params = {"input_columns":['MedInc', 'HouseAge', 'AveRooms',
'AveBedrms', 'Population', 'AveOccup',
'Latitude', 'Longitude'],
"response_column":"MedHouseVal",
"model_type":"regression",
"batch_size":(11, 50, 75),
"iter_max":(100, 301),
"lambda1":0.1,
"alpha":0.5,
"iter_num_no_change":60,
"tolerance":0.01,
"intercept":False,
"learning_rate":"INVTIME",
"initial_data":0.5,
"decay_rate":0.5,
"momentum":0.6,
"nesterov":True,
"local_sgd_iterations":1}
>>> # Required argument for model prediction and evaluation.
>>> eval_params = {"id_column": "id",
"accumulate": "MedHouseVal"}
>>> # Import trainer function and optimizer.
>>> from teradataml import SVM, GridSearch
>>> # Initialize the GridSearch optimizer with model trainer
>>> # function and parameter space required for model training.
>>> gs_obj = GridSearch(func=SVM, params=params)
>>> # Perform model optimization for SVM function.
>>> # Evaluation and prediction arguments are passed along with
>>> # training dataframe.
>>> gs_obj.fit(data=transform_obj.result, **eval_params)
>>> # View trained models.
>>> gs_obj.models
MODEL_ID DATA_ID PARAMETERS STATUS MAE
0 SVM_3 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.616772
1 SVM_0 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.660815
2 SVM_1 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.660815
3 SVM_2 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.616772
4 SVM_4 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.616772
5 SVM_5 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.616772
>>> # View model evaluation stats.
>>> gs_obj.model_stats
MODEL_ID DATA_ID PARAMETERS STATUS MAE
0 SVM_3 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.616772`
1 SVM_0 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.660815
2 SVM_1 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.660815
3 SVM_2 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.616772
4 SVM_4 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.616772
5 SVM_5 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.616772`
>>> # View best data, model ID and score.
>>> print("Best data ID: ", gs_obj.best_data_id)
Best data ID: DF_0
>>> print("Best model ID: ", gs_obj.best_model_id)
Best model ID: SVM_3
>>> print("Best model score: ",gs_obj.best_score_)
Best model score: 2.616772068334627
>>> # Performing prediction on sampled data using best trained model.
>>> test_data = transform_obj.result.iloc[:5]
>>> gs_pred = gs_obj.predict(newdata=test_data, **eval_params)
>>> print("Prediction result:
", gs_pred.result)
Prediction result:
id prediction MedHouseVal
0 686 0.202843 1.578
1 2018 0.149868 0.578
2 1754 0.211870 1.651
3 670 0.192414 1.922
4 244 0.247545 1.117
>>> # Perform evaluation using best model.
>>> gs_obj.evaluate()
############ result Output ############
MAE MSE MSLE MAPE MPE RMSE RMSLE ME R2 EV MPD MGD
0 2.616772 8.814968 0.0 101.876866 101.876866 2.969001 0.0 5.342344 -4.14622 -0.14862 NaN NaN
>>> # Retrieve any trained model.
>>> gs_obj.get_model("SVM_1")
############ output_data Output ############
iterNum loss eta bias
0 3 2.060386 0.028868 0.0
1 5 2.055509 0.022361 0.0
2 6 2.051982 0.020412 0.0
3 7 2.048387 0.018898 0.0
4 9 2.041521 0.016667 0.0
5 10 2.038314 0.015811 0.0
6 8 2.044882 0.017678 0.0
7 4 2.058757 0.025000 0.0
8 2 2.065932 0.035355 0.0
9 1 1.780877 0.050000 0.0
############ result Output ############
predictor estimate value
attribute
7 Latitude 0.155095 None
-9 Learning Rate (Initial) 0.050000 None
-17 OneClass SVM NaN FALSE
-14 Epsilon 0.100000 None
5 Population 0.000000 None
-12 Nesterov NaN TRUE
-5 BIC 73.297397 None
-7 Alpha 0.500000 Elasticnet
-3 Number of Observations 55.000000 None
0 (Intercept) 0.000000 None
>>> # Update the default model.
>>> gs_obj.set_model("SVM_1")
>>> # Example 2: Model trainer function. Performing hyperparameter-tuning
>>> # on SVM model trainer function using unlabeled multiple-dataframe.
>>> # Slicing transformed dataframe into two part to present
>>> # multiple-dataframe support.
>>> train_df_1 = transform_obj.result.iloc[:30]
>>> train_df_2 = transform_obj.result.iloc[30:]
>>> # Initialize the GridSearch optimizer with model trainer
>>> # function and parameter space required for model training.
>>> gs_obj = GridSearch(func=SVM, params=params)
>>> # Perform model optimization for SVM function for
>>> # unlabeled multiple-dataframe support.
>>> # Evaluation and prediction arguments are passed along with
>>> # training dataframe.
>>> gs_obj.fit(data=(train_df_1, train_df_2), **eval_params)
>>> # View trained models.
>>> gs_obj.models
MODEL_ID DATA_ID PARAMETERS STATUS MAE
0 SVM_3 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.650505
1 SVM_1 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.650505
2 SVM_2 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.326521
3 SVM_0 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.326521
4 SVM_7 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.650505
5 SVM_4 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.326521
6 SVM_6 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.326521
7 SVM_5 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.650505
8 SVM_9 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.650505
9 SVM_10 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.326521
10 SVM_11 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.650505
11 SVM_8 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.326521
>>> # View model evaluation stats.
>>> gs_obj.model_stats
MODEL_ID MAE MSE MSLE MAPE ... ME R2 EV MPD MGD
0 SVM_3 2.650505 8.459088 0.0 159.159527 ... 5.282729 -2.930531 0.333730 NaN NaN
1 SVM_1 2.650505 8.459088 0.0 159.159527 ... 5.282729 -2.930531 0.333730 NaN NaN
2 SVM_2 2.326521 6.218464 0.0 90.629648 ... 3.776410 -6.987358 -0.034968 NaN NaN
3 SVM_0 2.326521 6.218464 0.0 90.629648 ... 3.776410 -6.987358 -0.034968 NaN NaN
4 SVM_7 2.650505 8.459088 0.0 159.159527 ... 5.282729 -2.930531 0.333730 NaN NaN
5 SVM_4 2.326521 6.218464 0.0 90.629648 ... 3.776410 -6.987358 -0.034968 NaN NaN
6 SVM_6 2.326521 6.218464 0.0 90.629648 ... 3.776410 -6.987358 -0.034968 NaN NaN
7 SVM_5 2.650505 8.459088 0.0 159.159527 ... 5.282729 -2.930531 0.333730 NaN NaN
8 SVM_9 2.650505 8.459088 0.0 159.159527 ... 5.282729 -2.930531 0.333730 NaN NaN
9 SVM_10 2.326521 6.218464 0.0 90.629648 ... 3.776410 -6.987358 -0.034968 NaN NaN
10 SVM_11 2.650505 8.459088 0.0 159.159527 ... 5.282729 -2.930531 0.333730 NaN NaN
11 SVM_8 2.326521 6.218464 0.0 90.629648 ... 3.776410 -6.987358 -0.034968 NaN NaN
>>> # View best data, model ID and score.
>>> print("Best data ID: ", gs_obj.best_data_id)
Best data ID: DF_0
>>> print("Best model ID: ", gs_obj.best_model_id)
Best model ID: SVM_2
>>> print("Best model score: ",gs_obj.best_score_)
Best model score: 2.3265213466885375
>>> # Performing prediction on sampled data using best trained model.
>>> test_data = transform_obj.result.iloc[:5]
>>> gs_pred = gs_obj.predict(newdata=test_data, **eval_params)
>>> print("Prediction result:
", gs_pred.result)
Prediction result:
id prediction MedHouseVal
0 686 -0.214558 1.578
1 2018 0.224954 0.578
2 1754 -0.484374 1.651
3 670 -0.288802 1.922
4 244 -0.097476 1.117
>>> # Perform evaluation using best model.
>>> gs_obj.evaluate()
############ result Output ############
MAE MSE MSLE MAPE MPE RMSE RMSLE ME R2 EV MPD MGD
0 2.326521 6.218464 0.0 90.629648 90.629648 2.493685 0.0 3.77641 -6.987358 -0.034968 NaN NaN
>>> # Retrieve any trained model.
>>> gs_obj.get_model("SVM_1")
############ output_data Output ############
iterNum loss eta bias
0 3 2.078232 0.028868 0.0
1 5 2.049456 0.022361 0.0
2 6 2.037157 0.020412 0.0
3 7 2.028186 0.018898 0.0
4 9 2.012801 0.016667 0.0
5 10 2.007469 0.015811 0.0
6 8 2.020026 0.017678 0.0
7 4 2.063343 0.025000 0.0
8 2 2.092763 0.035355 0.0
9 1 2.112669 0.050000 0.0
############ result Output ############
predictor estimate value
attribute
7 Latitude 0.077697 None
-9 Learning Rate (Initial) 0.050000 None
-17 OneClass SVM NaN FALSE
-14 Epsilon 0.100000 None
5 Population -0.120322 None
-12 Nesterov NaN TRUE
-5 BIC 50.583018 None
-7 Alpha 0.500000 Elasticnet
-3 Number of Observations 31.000000 None
0 (Intercept) 0.000000 None
>>> # Update the default model.
>>> gs_obj.set_model("SVM_1")
>>> # Example 3: Model trainer function. Performing hyperparameter-tuning
>>> # on SVM model trainer function using labeled multiple-dataframe.
>>> # Initialize the GridSearch optimizer with model trainer
>>> # function and parameter space required for model training.
>>> gs_obj = GridSearch(func=SVM, params=params)
>>> # Perform model optimization for SVM function for
>>> # labeled multiple-dataframe support.
>>> # Evaluation and prediction arguments are passed along with
>>> # training dataframe.
>>> gs_obj.fit(data={"Data-1":train_df_1, "Data-2":train_df_2}, **eval_params)
>>> # View trained models.
>>> gs_obj.models
MODEL_ID DATA_ID PARAMETERS STATUS MAE
0 SVM_1 Data-2 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.286463
1 SVM_3 Data-2 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.286463
2 SVM_2 Data-1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.156109
3 SVM_0 Data-1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.156109
4 SVM_7 Data-2 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.286463
5 SVM_4 Data-1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.156109
6 SVM_5 Data-2 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.286463
7 SVM_6 Data-1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.156109
8 SVM_10 Data-1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.156109
9 SVM_8 Data-1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.156109
10 SVM_9 Data-2 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.286463
11 SVM_11 Data-2 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.286463
>>> # View model evaluation stats.
>>> gs_obj.model_stats
MODEL_ID MAE MSE MSLE MAPE ... ME R2 EV MPD MGD
0 SVM_1 2.286463 5.721906 0.115319 120.188468 ... 3.280316 -3.436736 0.616960 NaN NaN
1 SVM_3 2.286463 5.721906 0.115319 120.188468 ... 3.280316 -3.436736 0.616960 NaN NaN
2 SVM_2 2.156109 6.986356 0.000000 97.766138 ... 4.737632 -2.195437 -0.235152 NaN NaN
3 SVM_0 2.156109 6.986356 0.000000 97.766138 ... 4.737632 -2.195437 -0.235152 NaN NaN
4 SVM_7 2.286463 5.721906 0.115319 120.188468 ... 3.280316 -3.436736 0.616960 NaN NaN
5 SVM_4 2.156109 6.986356 0.000000 97.766138 ... 4.737632 -2.195437 -0.235152 NaN NaN
6 SVM_5 2.286463 5.721906 0.115319 120.188468 ... 3.280316 -3.436736 0.616960 NaN NaN
7 SVM_6 2.156109 6.986356 0.000000 97.766138 ... 4.737632 -2.195437 -0.235152 NaN NaN
8 SVM_10 2.156109 6.986356 0.000000 97.766138 ... 4.737632 -2.195437 -0.235152 NaN NaN
9 SVM_8 2.156109 6.986356 0.000000 97.766138 ... 4.737632 -2.195437 -0.235152 NaN NaN
10 SVM_9 2.286463 5.721906 0.115319 120.188468 ... 3.280316 -3.436736 0.616960 NaN NaN
11 SVM_11 2.286463 5.721906 0.115319 120.188468 ... 3.280316 -3.436736 0.616960 NaN NaN
[12 rows x 13 columns]
>>> # View best data, model ID and score.
>>> print("Best data ID: ", gs_obj.best_data_id)
Best data ID: Data-1
>>> print("Best model ID: ", gs_obj.best_model_id)
Best model ID: SVM_2
>>> print("Best model score: ",gs_obj.best_score_)
Best model score: 2.156108718480682
>>> # Performing prediction on sampled data using best trained model.
>>> test_data = transform_obj.result.iloc[:5]
>>> gs_pred = gs_obj.predict(newdata=test_data, **eval_params)
>>> print("Prediction result:
", gs_pred.result)
Prediction result:
id prediction MedHouseVal
0 686 -0.512750 1.578
1 2018 0.065364 0.578
2 1754 -0.849449 1.651
3 670 -0.657097 1.922
4 244 -0.285946 1.117
>>> # Perform evaluation using best model.
>>> gs_obj.evaluate()
############ result Output ############
MAE MSE MSLE MAPE MPE RMSE RMSLE ME R2 EV MPD MGD
0 2.156109 6.986356 0.0 97.766138 83.453982 2.643172 0.0 4.737632 -2.195437 -0.235152 NaN NaN
>>> # Retrieve any trained model.
>>> gs_obj.get_model("SVM_1")
############ output_data Output ############
iterNum loss eta bias
0 3 2.238049 0.028868 0.0
1 5 2.198618 0.022361 0.0
2 6 2.183347 0.020412 0.0
3 7 2.171550 0.018898 0.0
4 9 2.154619 0.016667 0.0
5 10 2.147124 0.015811 0.0
6 8 2.162718 0.017678 0.0
7 4 2.217790 0.025000 0.0
8 2 2.257826 0.035355 0.0
9 1 2.286324 0.050000 0.0
############ result Output ############
predictor estimate value
attribute
-7 Alpha 0.500000 Elasticnet
-3 Number of Observations 31.000000 None
5 Population -0.094141 None
0 (Intercept) 0.000000 None
-17 OneClass SVM NaN FALSE
-16 Kernel NaN LINEAR
-1 Loss Function NaN EPSILON_INSENSITIVE
7 Latitude 0.169825 None
-9 Learning Rate (Initial) 0.050000 None
-14 Epsilon 0.100000 None
>>> # Update the default model.
>>> gs_obj.set_model("SVM_1")
>>> # Example 4: Model trainer function. Performing hyperparameter-tuning
>>> # on SVM model trainer function by passing unlabeled
>>> # multiple-dataframe as model hyperparameter.
>>> # Define parameter space for model training.
>>> params = {"data":(train_df_1, train_df_2),
"input_columns":['MedInc', 'HouseAge', 'AveRooms',
'AveBedrms', 'Population', 'AveOccup',
'Latitude', 'Longitude'],
"response_column":"MedHouseVal",
"model_type":"regression",
"batch_size":(11, 50, 75),
"iter_max":(100, 301),
"lambda1":0.1,
"alpha":0.5,
"iter_num_no_change":60,
"tolerance":0.01,
"intercept":False,
"learning_rate":"INVTIME",
"initial_data":0.5,
"decay_rate":0.5,
"momentum":0.6,
"nesterov":True,
"local_sgd_iterations":1}
>>> # Initialize the GridSearch optimizer with model trainer
>>> # function and parameter space required for model training.
>>> gs_obj = GridSearch(func=SVM, params=params)
>>> # Perform model optimization for SVM function for
>>> # labeled multiple-dataframe support.
>>> # Evaluation and prediction arguments are passed along with
>>> # training dataframe.
>>> gs_obj.fit(**eval_params)
>>> # View trained models.
>>> gs_obj.models
MODEL_ID DATA_ID PARAMETERS STATUS MAE
0 SVM_0 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.007936
1 SVM_1 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.517338
2 SVM_3 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.517338
3 SVM_2 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.007936
4 SVM_5 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.517338
5 SVM_7 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.517338
6 SVM_6 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.007936
7 SVM_4 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.007936
8 SVM_9 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.517338
9 SVM_8 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.007936
10 SVM_11 DF_1 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.517338
11 SVM_10 DF_0 {'input_columns': ['MedInc', 'HouseAge', 'AveR... PASS 2.007936
>>> # View model evaluation stats.
>>> gs_obj.model_stats
MODEL_ID MAE MSE MSLE MAPE ... ME R2 EV MPD MGD
0 SVM_0 2.007936 5.402427 0.007669 88.199346 ... 3.981598 -6.898063 -1.003772 NaN NaN
1 SVM_1 2.517338 7.470182 0.000000 118.722467 ... 4.035658 -7.827958 -0.716572 NaN NaN
2 SVM_3 2.517338 7.470182 0.000000 118.722467 ... 4.035658 -7.827958 -0.716572 NaN NaN
3 SVM_2 2.007936 5.402427 0.007669 88.199346 ... 3.981598 -6.898063 -1.003772 NaN NaN
4 SVM_5 2.517338 7.470182 0.000000 118.722467 ... 4.035658 -7.827958 -0.716572 NaN NaN
5 SVM_7 2.517338 7.470182 0.000000 118.722467 ... 4.035658 -7.827958 -0.716572 NaN NaN
6 SVM_6 2.007936 5.402427 0.007669 88.199346 ... 3.981598 -6.898063 -1.003772 NaN NaN
7 SVM_4 2.007936 5.402427 0.007669 88.199346 ... 3.981598 -6.898063 -1.003772 NaN NaN
8 SVM_9 2.517338 7.470182 0.000000 118.722467 ... 4.035658 -7.827958 -0.716572 NaN NaN
9 SVM_8 2.007936 5.402427 0.007669 88.199346 ... 3.981598 -6.898063 -1.003772 NaN NaN
10 SVM_11 2.517338 7.470182 0.000000 118.722467 ... 4.035658 -7.827958 -0.716572 NaN NaN
11 SVM_10 2.007936 5.402427 0.007669 88.199346 ... 3.981598 -6.898063 -1.003772 NaN NaN
[12 rows x 13 columns]
>>> # View best data, model ID and score.
>>> print("Best data ID: ", gs_obj.best_data_id)
Best data ID: DF_0
>>> print("Best model ID: ", gs_obj.best_model_id)
Best model ID: SVM_0
>>> print("Best model score: ",gs_obj.best_score_)
Best model score: 2.0079362549355104
>>> # Performing prediction on sampled data using best trained model.
>>> test_data = transform_obj.result.iloc[:5]
>>> gs_pred = gs_obj.predict(newdata=test_data, **eval_params)
>>> print("Prediction result:
", gs_pred.result)
Prediction result:
id prediction MedHouseVal
0 686 -0.365955 1.578
1 2018 0.411846 0.578
2 1754 -0.634807 1.651
3 670 -0.562927 1.922
4 244 -0.169730 1.117
>>> # Perform evaluation using best model.
>>> gs_obj.evaluate()
############ result Output ############
MAE MSE MSLE MAPE MPE RMSE RMSLE ME R2 EV MPD MGD
0 2.007936 5.402427 0.007669 88.199346 88.199346 2.324312 0.087574 3.981598 -6.898063 -1.003772 NaN NaN
>>> # Retrieve any trained model.
>>> gs_obj.get_model("SVM_1")
############ output_data Output ############
iterNum loss eta bias
0 3 2.154842 0.028868 0.0
1 5 2.129916 0.022361 0.0
2 6 2.118539 0.020412 0.0
3 7 2.107991 0.018898 0.0
4 9 2.089022 0.016667 0.0
5 10 2.080426 0.015811 0.0
6 8 2.098182 0.017678 0.0
7 4 2.142030 0.025000 0.0
8 2 2.168233 0.035355 0.0
9 1 2.186740 0.050000 0.0
############ result Output ############
predictor estimate value
attribute
7 Latitude 0.010463 None
-9 Learning Rate (Initial) 0.050000 None
-17 OneClass SVM NaN FALSE
-14 Epsilon 0.100000 None
5 Population -0.348591 None
-12 Nesterov NaN TRUE
-5 BIC 50.585888 None
-7 Alpha 0.500000 Elasticnet
-3 Number of Observations 31.000000 None
0 (Intercept) 0.000000 None
>>> # Update the default model.
>>> gs_obj.set_model("SVM_1")
>>> # Example 5: Non-Model trainer function. Performing GridSearch
>>> # on AntiSelect model trainer function.
>>> # Load the example dataset.
>>> load_example_data("teradataml", "titanic")
>>> # Create teradaraml dataframe.
>>> titanic = DataFrame.from_table("titanic")
>>> # Define the non-model trainer function parameter space.
>>> # Include input data in parameter space for non-model trainer function.
>>> params = {"data":titanic, "exclude":(
['survived', 'name', 'age'],
["ticket", "parch", "sex", "age"])}
>>> # Import non-model trainer function and optimizer.
>>> from teradataml import Antiselect, GridSearch
>>> # Initialize the GridSearch optimizer with non-model trainer
>>> # function and parameter space required for non-model training.
>>> gs_obj = GridSearch(func=Antiselect, params=params)
>>> # Perform execution of Antiselect function.
>>> gs_obj.fit()
>>> # View trained models.
>>> gs_obj.models
MODEL_ID PARAMETERS STATUS
0 ANTISELECT_1 {'data': '"titanic"', 'exclude': ['ticket', 'p... PASS
1 ANTISELECT_0 {'data': '"titanic"', 'exclude': ['survived', ... PASS
>>> # Retrieve any trained model using "MODEL_ID".
>>> gs_obj.get_model("ANTISELECT_1")
############ result Output ############
passenger survived pclass name sibsp fare cabin embarked
0 162 1 2 Watt, Mrs. James (Elizabeth "Bessie" Inglis Milne) 0 15.7500 None S
1 591 0 3 Rintamaki, Mr. Matti 0 7.1250 None S
2 387 0 3 Goodwin, Master. Sidney Leonard 5 46.9000 None S
3 469 0 3 Scanlan, Mr. James 0 7.7250 None Q
4 326 1 1 Young, Miss. Marie Grice 0 135.6333 C32 C
5 265 0 3 Henry, Miss. Delia 0 7.7500 None Q
6 530 0 2 Hocking, Mr. Richard George 2 11.5000 None S
7 244 0 3 Maenpaa, Mr. Matti Alexanteri 0 7.1250 None S
8 61 0 3 Sirayanian, Mr. Orsen 0 7.2292 None C
9 122 0 3 Moore, Mr. Leonard Charles 0 8.0500 None S