MLPMultiTaskImputer

class hana_ml.algorithms.pal.mlp_imputer.MLPMultiTaskImputer(overlapped_variable=None, max_imputer_rows=None, imputer_int_mask_value=None, hidden_layer_size=None, activation=None, batch_size=None, num_epochs=None, random_state=None, use_batchnorm=None, learning_rate=None, optimizer=None, dropout_prob=None, training_percentage=None, early_stop=None, normalization=None, warmup_epochs=None, patience=None, save_best_model=None, training_style=None, network_type=None, embedded_num=None, residual_num=None, resampling_method=None, evaluation_metric=None, fold_num=None, repeat_times=None, param_search_strategy=None, random_search_times=None, timeout=None, progress_indicator_id=None, reduction_rate=None, aggressive_elimination=None, param_range=None, param_values=None)

Multi-Task Multilayer Perceptron Imputer.

Imputer mode extends the Multi-Task MLP classifier with the ability to train a network that can impute (predict) missing categorical values in a dataset. It is activated by declaring one or more overlapped columns via overlapped_variable.

In imputer mode, selected columns serve a dual role: they are both targets (what the network learns to predict) and masked inputs (what the network uses as features, with values randomly hidden during training). The network is trained on an upsampled masked table and learns to predict the correct values for all targets, including the overlapped ones.

Note

Imputer mode is only supported for classification tasks. It cannot be combined with finetune mode.

The same three imputer parameters (overlapped_variable, max_imputer_rows, imputer_int_mask_value) are also exposed on MLPMultiTaskClassifier. This class is a convenience wrapper that hard-enforces the imputer constraints (functionality=0, finetune=False, and overlapped_variable is required).

Parameters
overlapped_variablestr, list of str, list of tuple, or dict

Required. Declares one or more dual-role columns. Each such column serves as both a target (auto-promoted, no need to list in label) and a masked feature input.

Supported formats:

  • str: a single column name, using default mask probability (0.5) and no per-column INT mask sentinel.

  • list of str: multiple column names, all using defaults.

  • list of tuple: each tuple encodes a single overlapped column as (column_name,), (column_name, mask_prob), or (column_name, int_mask_value, mask_prob). Use None for a slot to keep its default. Examples:

    [('V002',), ('V003', 999, 0.8)]

  • dict: keys are column names, values are either

    • None / mask_prob (float in [0.0, 1.0)), or

    • (int_mask_value, mask_prob) tuple with None allowed for either slot.

    Example: {'V002': None, 'V003': (999, 0.8)}.

Overlapped columns are automatically promoted to targets — you do not need to list them in label. A column cannot appear in both label and overlapped_variable.

max_imputer_rowsint, optional

Upper bound on total rows in the upsampled masked training table, to prevent out-of-memory. It should not be smaller than the input training row count.

Defaults to 10000000.

imputer_int_mask_valueint, optional

Global default mask sentinel for INT categorical overlapped columns. Overridden per-column by the int_mask_value supplied on the corresponding entry of overlapped_variable.

Defaults to INT_MAX.

hidden_layer_sizelist (tuple) of int, optional

Specifies the sizes of all hidden layers in the neural network.

Mandatory and valid only when network_type is 'basic'.

activationstr, optional

Specifies the activation function for the hidden layer.

Valid activation functions include:

  • 'sigmoid'

  • 'tanh'

  • 'relu'

  • 'leaky-relu'

  • 'elu'

  • 'gelu'

Defaults to 'relu'.

batch_sizeint, optional

Specifies the number of training samples in a batch.

Defaults to 16.

num_epochsint, optional

Specifies the maximum number of training epochs.

Defaults to 100.

random_stateint, optional

Specifies the seed for random generation. Use system time when 0 is specified.

Defaults to 0.

use_batchnormbool, optional

Specifies whether to use batch-normalization in each hidden layer.

Defaults to True.

learning_ratefloat, optional

Specifies the learning rate for gradient based optimizers.

Defaults to 0.001.

optimizerstr, optional

Specifies the optimizer for training the neural network.

  • 'sgd'

  • 'rmsprop'

  • 'adam'

  • 'adagrad'

Defaults to 'adam'.

dropout_probfloat, optional

Specifies the dropout probability applied when training the neural network.

Defaults to 0.0.

training_percentagefloat, optional

Specifies the percentage of input data used for training (with the rest of input data used for validation).

Defaults to 0.9.

early_stopbool, optional

Specifies whether to use the automatic early stopping method or not.

Defaults to True.

normalizationstr, optional

Specifies the normalization type for input data.

  • 'no'

  • 'z-transform'

  • 'scalar'

Defaults to 'no'.

warmup_epochsint, optional

Specifies the least number of epochs to wait before executing the auto early stopping method.

Defaults to 5.

patienceint, optional

Specifies the number of epochs to wait before terminating the training if no improvement is shown.

Defaults to 5.

save_best_modelbool, optional

Specifies whether to save the best model (regarding to the minimum loss on the validation set).

Defaults to False.

training_style{'batch', 'stochastic'}, optional

Specifies the training style of the learning algorithm.

Defaults to 'stochastic'.

network_type{'basic', 'resnet'}, optional

Specifies the structure of the underlying neural-network.

Defaults to 'basic'.

embedded_numint, optional

Specifies the embedding dimension of ResNet for the input data.

Mandatory and valid when network_type is 'resnet'.

residual_numint, optional

Specifies the number of residual blocks in ResNet.

Mandatory and valid when network_type is 'resnet'.

Attributes
model_DataFrame

The trained MLP imputer model.

train_log_DataFrame

Provides training errors among iterations.

stats_DataFrame

Names and values of statistics.

optim_param_DataFrame

Provides optimal parameters selected.

Available only when parameter selection is triggered.

Methods

create_model_state([model, function, ...])

Create PAL model state.

delete_model_state([state])

Delete PAL model state.

fit([data, key, features, label, ...])

Fit function for Multi-Task MLP Imputer.

predict([data, key, features, verbose, model])

Predict method for the Multi-Task MLP Imputer.

set_model_state(state)

Set the model state by state information.

Examples

Consider a training table with two "pure" target columns (TARGET1, TARGET2) and two "overlapped" columns (V003, V004) that we also want the network to learn to reconstruct:

>>> imputer = MLPMultiTaskImputer(
...     hidden_layer_size=[4, 4],
...     learning_rate=0.02,
...     num_epochs=20,
...     batch_size=5,
...     random_state=1234,
...     patience=2,
...     training_percentage=0.7,
...     overlapped_variable=[('V003',), ('V004', 999, 0.8)],
...     imputer_int_mask_value=999)
>>> imputer.fit(data=train_data, key='ID',
...             label=['TARGET1', 'TARGET2'],
...             categorical_variable='V004')

Predict — supply the mask sentinel for missing values:

  • For STRING overlapped columns, use the string 'PAL_MLP_MASK'.

  • For INT overlapped columns, use the sentinel declared for that column (or imputer_int_mask_value if none was given).

>>> pred = imputer.predict(data=predict_data, key='ID')
fit(data=None, key=None, features=None, label=None, categorical_variable=None, model_table_name=None)

Fit function for Multi-Task MLP Imputer.

Parameters
dataDataFrame

DataFrame containing the training data.

keystr, optional

Name of the ID column.

If key is not provided, then:

  • if data is indexed by a single column, then key defaults to that index column;

  • otherwise, it is assumed that data contains no ID column.

featuresa list of str, optional

Names of the feature columns.

If features is not provided, it defaults to all the non-ID, non-label columns.

labelstr or a list of str, optional

Name(s) of the "pure" target columns — targets that are NOT also overlapped features. Columns declared in overlapped_variable are automatically promoted to targets by PAL and MUST NOT be listed here.

categorical_variablestr or a list of str, optional

Specifies which INTEGER columns should be treated as categorical. For INT overlapped columns, list them here so PAL treats them as categorical targets.

No default value.

model_table_namestr, optional

Specifies the name of the model table.

Defaults to None.

Returns
MLPMultiTaskImputer

A fitted object of class "MLPMultiTaskImputer".

predict(data=None, key=None, features=None, verbose=None, model=None)

Predict method for the Multi-Task MLP Imputer.

The predict table uses the original column names for the overlapped columns. Supply the mask sentinel values to indicate missing data:

  • For STRING overlapped columns, use the string 'PAL_MLP_MASK'.

  • For INT overlapped columns, use the sentinel declared for that column (or imputer_int_mask_value if none was given per column, or INT_MAX if neither was set).

Parameters
dataDataFrame

DataFrame containing the data for prediction purpose.

keystr, optional

Name of the ID column.

Mandatory if data is not indexed, or the index of data contains multiple columns.

Defaults to the single index column of data if not provided.

featuresa list of str, optional

Names of the feature columns.

If features is not provided, it defaults to all the non-ID, non-label columns.

verbosebool, optional

If True, output scoring probabilities for each class.

Defaults to False.

modelDataFrame, optional

The model to use for prediction. Defaults to self.model_.

Returns
DataFrame
Predict result with columns:
  • ID

  • TARGET (target/overlapped column name)

  • SCORE (predicted value as string)

  • CONFIDENCE (associated probability)

create_model_state(model=None, function=None, pal_funcname='PAL_MLP_MULTI_TASK', state_description=None, force=False)

Create PAL model state.

Parameters
modelDataFrame, optional

Specify the model for AFL state.

Defaults to self.model_.

functionstr, optional

Specify the function in the unified API.

A placeholder parameter, not effective for MultiTask MLP.

pal_funcnameint or str, optional

PAL function name.

Defaults to 'PAL_MLP_MULTI_TASK'.

state_descriptionstr, optional

Description of the state as model container.

Defaults to None.

forcebool, optional

If True it will delete the existing state.

Defaults to False.

delete_model_state(state=None)

Delete PAL model state.

Parameters
stateDataFrame, optional

Specify the state.

Defaults to self.state.

set_model_state(state)

Set the model state by state information.

Parameters
state: DataFrame or dict

If state is DataFrame, it has the following structure:

  • NAME: VARCHAR(100), it must have STATE_ID, HINT, HOST and PORT.

  • VALUE: VARCHAR(1000), the values according to NAME.

If state is dict, the key must have STATE_ID, HINT, HOST and PORT.

Inherited Methods from PALBase

Besides those methods mentioned above, the MLPMultiTaskImputer class also inherits methods from PALBase class, please refer to PAL Base for more details.