Skip to contents

Impute features by a constant value.

Format

R6Class object inheriting from PipeOpImpute/PipeOp.

Construction

PipeOpImputeConstant$new(id = "imputeconstant", param_vals = list())

  • id :: character(1)
    Identifier of resulting object, default "imputeconstant".

  • param_vals :: named list
    List of hyperparameter settings, overwriting the hyperparameter settings that would otherwise be set during construction. Default list().

Input and Output Channels

Input and output channels are inherited from PipeOpImpute.

The output is the input Task with all affected features missing values imputed by the value of the constant parameter.

State

The $state is a named list with the $state elements inherited from PipeOpImpute.

The $state$model contains the value of the constant parameter that is used for imputation.

Parameters

The parameters are the parameters inherited from PipeOpImpute, as well as:

  • constant :: atomic(1)
    The constant value that should be used for the imputation, atomic vector of length 1. The atomic mode must match the type of the features that will be selected by the affect_columns parameter and this will be checked during imputation. This is a required hyperparameter and needs to be set by the user.

  • check_levels :: logical(1)
    Should be checked whether the constant value is a valid level of factorial features (i.e., it already is a level)? Raises an error if unsuccessful. This check is only performed for factorial features (i.e., factor, ordered; skipped for character). Initialized to TRUE.
    Note that empty factor levels can be a problem for many Learners. Thus, PipeOpImputeOOR is the preferred choice for creating new levels, since it is designed to impute out-of-range values and offers a more explicit control for handling potentially problematic behavior.

Internals

The constructor is called with empty_level_control set to "always", to allow the creation of a new empty level for factor and ordered (but not character) features during training, if constant is not an already existing level and check_levels is set to FALSE. This has no impact if check_levels is TRUE, since in that case an error would be raised before imputation.

Fields

Only fields inherited from PipeOp.

Methods

Only methods inherited from PipeOpImpute/PipeOp.

See also

https://mlr-org.com/pipeops.html

Other PipeOps: PipeOp, PipeOpEncodePL, PipeOpEnsemble, PipeOpImpute, PipeOpTargetTrafo, PipeOpTaskPreproc, PipeOpTaskPreprocSimple, mlr_pipeops, mlr_pipeops_adas, mlr_pipeops_blsmote, mlr_pipeops_boxcox, mlr_pipeops_branch, mlr_pipeops_chunk, mlr_pipeops_classbalancing, mlr_pipeops_classifavg, mlr_pipeops_classweights, mlr_pipeops_classweightsex, mlr_pipeops_colapply, mlr_pipeops_collapsefactors, mlr_pipeops_colroles, mlr_pipeops_copy, mlr_pipeops_datefeatures, mlr_pipeops_decode, mlr_pipeops_encode, mlr_pipeops_encodeimpact, mlr_pipeops_encodelmer, mlr_pipeops_encodeplquantiles, mlr_pipeops_encodepltree, mlr_pipeops_featureunion, mlr_pipeops_filter, mlr_pipeops_fixfactors, mlr_pipeops_histbin, mlr_pipeops_ica, mlr_pipeops_imputehist, mlr_pipeops_imputelearner, mlr_pipeops_imputemean, mlr_pipeops_imputemedian, mlr_pipeops_imputemode, mlr_pipeops_imputeoor, mlr_pipeops_imputesample, mlr_pipeops_info, mlr_pipeops_isomap, mlr_pipeops_kernelpca, mlr_pipeops_learner, mlr_pipeops_learner_pi_cvplus, mlr_pipeops_learner_quantiles, mlr_pipeops_materialize, mlr_pipeops_missind, mlr_pipeops_modelmatrix, mlr_pipeops_multiplicityexply, mlr_pipeops_multiplicityimply, mlr_pipeops_mutate, mlr_pipeops_nearmiss, mlr_pipeops_nmf, mlr_pipeops_nop, mlr_pipeops_ovrsplit, mlr_pipeops_ovrunite, mlr_pipeops_pca, mlr_pipeops_proxy, mlr_pipeops_quantilebin, mlr_pipeops_randomprojection, mlr_pipeops_randomresponse, mlr_pipeops_regravg, mlr_pipeops_removeconstants, mlr_pipeops_renamecolumns, mlr_pipeops_replicate, mlr_pipeops_rowapply, mlr_pipeops_scale, mlr_pipeops_scalemaxabs, mlr_pipeops_scalerange, mlr_pipeops_select, mlr_pipeops_smote, mlr_pipeops_smotenc, mlr_pipeops_spatialsign, mlr_pipeops_splines, mlr_pipeops_subsample, mlr_pipeops_targetinvert, mlr_pipeops_targetmutate, mlr_pipeops_targettrafoscalerange, mlr_pipeops_textvectorizer, mlr_pipeops_threshold, mlr_pipeops_tomek, mlr_pipeops_tunethreshold, mlr_pipeops_unbranch, mlr_pipeops_updatetarget, mlr_pipeops_vtreat, mlr_pipeops_yeojohnson

Other Imputation PipeOps: PipeOpImpute, mlr_pipeops_imputehist, mlr_pipeops_imputelearner, mlr_pipeops_imputemean, mlr_pipeops_imputemedian, mlr_pipeops_imputemode, mlr_pipeops_imputeoor, mlr_pipeops_imputesample

Examples

library("mlr3")

task = tsk("diabetes")
task$missings()
#> diabetes      age  glucose  insulin     mass pedigree pregnant pressure 
#>        0        0        5      405       13        0        0       35 
#>  triceps 
#>      251 

# impute missing values of the numeric feature "glucose" by the constant value -999
po = po("imputeconstant", param_vals = list(
  constant = -999, affect_columns = selector_name("glucose"))
)
new_task = po$train(list(task = task))[[1]]
new_task$missings()
#> diabetes      age  insulin     mass pedigree pregnant pressure  triceps 
#>        0        0      405       13        0        0       35      251 
#>  glucose 
#>        0 
new_task$data(cols = "glucose")[[1]]
#>   [1]  194  129  132  184  108  117  100   88   73  126  122   87   99  112   80
#>  [16]  111   82  144  126   97  142   87  145   88   88  102  106  106   87  169
#>  [31]  111  179  126   87  122  101  158  111  165   87  112   72  175   78  112
#>  [46]  142  100   96  113  147  141  167  127  122  107  111  118  119  199  128
#>  [61]  144  194  116  124  165  134  106   88   88  128  129  112  115   88  115
#>  [76]   99  129  127  124  103  108  165  137  112  126  137  173  165  128  126
#>  [91]   87   85  129  128  191   80  115  122  111  138  165  111   88  106  135
#> [106]  117  111  146  150   90   96  111  100  160  119  142  163  101   80   88
#> [121]  158  137   57  147  104  147  191  124  128  171   57   82  137  134  113
#> [136]  163  168  107  126  181  111  101   97  165  170   99  112  117  112  134
#> [151]  111   97  165  146  129   97  112  105  119  165  165  184  130  128   99
#> [166]  131  173  103  169   97  124  165  112  191   93  160  106  129  100  103
#> [181]  103  111   97  128  194  104  103  147  134  145  180   87  106  144  181
#> [196]  158  181  175   99  173   87  156   99  117  184  165  129   93  117  117
#> [211]  119  167  131  191   99   88  134   88  122  194  181  137  196  126   94
#> [226]  180  158  144  103  126  112  128   95 -999  117  107  119  121  112  182
#> [241]  158  100  134   83  191  108  106  132  160  117  128   99  136   93  165
#> [256]  127  128  194  128  119  111  106  106  141  111  106  191  124  113   91
#> [271]   82   86   97  155  137  115  120  107  102  117   91  103  132  134  182
#> [286]  165  160   97  194  108  135  144  131  144   86  106  111  109   92  112
#> [301]   80   87  137  148   99  101  124  112  146  131  191  101  131  167  112
#> [316]   88  165  107  102  119  136  134   93   97   90   91   92  152  194  128
#> [331]  122  147  142   96  132  134  129  128  175   91  129  124  121   88  112
#> [346]  101   89  147   73  144  124  167   97  104   83   82   78  169  181  102
#> [361]   97   88  169  111  144  147  102   95  189  152  128  126  175  108   76
#> [376]  112  165   87  181  129   88  112   92  129   95   91  121  128  189  124
#> [391]  126  135   73   96  116  112  169  127  129  168  101  144  170  194  113
#> [406]  165  122  128  181  137  173   88  181   87   93  138   88  173  131   99
#> [421]   95  128  194  189  128   78  116   85  119  142  113   90  147  111  141
#> [436]  181  106  191   97  135  121   99  111  129  129  106   96  106   65  130
#> [451]   82 -999   97  126  165  144  128  107  111  102   88  131  169   78  134
#> [466]  104  106  107  112  100  114  101  109  113  156   85  155   95  102  173
#> [481]  104  191  144  115  106   87  199   87  132  101   97  196  126  119  194
#> [496]   88  184  160  181  111  173  147  181   88  194   84  117  168  191  189
#> [511]  181  112  117   88  154  195  128  119  129  115   97  152  112 -999  128
#> [526]  162  167  179   99   97  128  111   99  119   99  119  165   95  106  112
#> [541]   88  103  106  196  122   80  108  119   88  106   89  112   85  119   87
#> [556]  119   73  146   83  122   92  112  103  165   99  181  131   88   88  170
#> [571]   97   98  109  102  106  119  180  156  137  129  107  116  116  119  144
#> [586]  191  126  115   86  191  104  126  162  119  184  128  137  119   71  134
#> [601]  111  156  147  100   88   99   85   82  160  122  116   93  181   91  126
#> [616]  106  126  134   90  134  147   88  184   97  137 -999   80   76   57  112
#> [631]  137  191  181   86   81  195  147  162  142  160  160  147   82  128  103
#> [646]  184  165  124  117  113  101  181   87  126  131  112  129  154   99  150
#> [661]  124  113  147  138  138  112   91  137  169  137  162   91  100  129  132
#> [676]  103   65  112  106  111  165  181   88  130  181  128   84   96  170  106
#> [691]  112  160  144   88  156  116  154  140  121  106  134  127   95  106  126
#> [706]  160   99  101  113  115  119  119  175  194  104  147  128  180  132   87
#> [721]  172  112  120   92  115  173   98   87   96  172   97   95  184  169  131
#> [736]   96  129  179   91  112   99  124  128   87   97  111   78  107  137  101
#> [751]  134  127   99  116  160  181  100   99 -999   88  113  120  179   92  181
#> [766]  130  146  115