Skip to contents

Replaces numeric features with columns representing spline basis expansions.

Depending on the type parameter, constructs polynomial B-splines splines::bs() or natural cubic splines splines::ns() for the respective column.

Format

R6Class object inheriting from PipeOpTaskPreproc/PipeOp.

Construction

po("splines", param_vals = list())

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

  • 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 PipeOpTaskPreproc.

The output is the input Task with the selected columns transformed according to the specified Splines Method.

State

The $state is a named list with the $state elements inherited from PipeOpTaskPreproc. After training the Boundary.knots will be given to the $state.

Parameters

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

  • type :: character(1)
    Controls the type of splines that are to be created. Can be either polynomial (splines::bs) or natural (splines::ns). Initializied to "natural".

  • df :: integer(1)
    Number of degrees of freedom for calculation of the spline basis matrix. Initialized to NULL. Depending on type, see either splines::bs() or splines::ns().

  • knots :: named list
    Internal breakpoints that define the spline, given as a named list of numeric vectors, where each name corresponds to a feature and its value specifies the knots for that feature. Default is NULL. Depending on type, see either splines::bs() or splines::ns().

  • intercept :: logical(1)
    If TRUE, an intercept is included in the basis. Default is FALSE. Depending on type, see either splines::bs() or splines::ns().

  • degree :: integer(1)
    Degree of the polynomial used to compute polynomial splines. Only used if type is "polynomial". Default is 3. See splines::bs().

  • Boundary.knots :: named list
    Boundary points at which to anchor the spline basis, given as a named list of numeric vectors, where each name corresponds to a feature and its value specifies the boundary points for that feature. Default is NULL. Depending on type, see either splines::bs() or splines::ns().

Internals

Creates a spline basis using either splines::bs or splines::ns depending on the hyperparameter type. After training, the Boundary.knots that were either provided by the user or calculated during training are stored in the PipeOp's $state.

Fields

Only fields inherited from PipeOp.

Methods

Only methods inherited from PipeOpTaskPreproc/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_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_imputeconstant, 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_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_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

Examples

library("mlr3")

task = tsk("iris")
pop = po("splines")

pop$train(list(task))[[1]]$data()
#>        Species Petal.Length Petal.Width Sepal.Length Sepal.Width
#>         <fctr>        <num>       <num>        <num>       <num>
#>   1:    setosa   0.05435822  0.03340766   0.17817416   0.5011148
#>   2:    setosa   0.05435822  0.03340766   0.13363062   0.3340766
#>   3:    setosa   0.04076866  0.03340766   0.08908708   0.4008919
#>   4:    setosa   0.06794777  0.03340766   0.06681531   0.3674842
#>   5:    setosa   0.05435822  0.03340766   0.15590239   0.5345225
#>  ---                                                            
#> 146: virginica   0.57076130  0.73496842   0.53452248   0.3340766
#> 147: virginica   0.54358219  0.60133779   0.44543540   0.1670383
#> 148: virginica   0.57076130  0.63474545   0.48997894   0.3340766
#> 149: virginica   0.59794041  0.73496842   0.42316363   0.4677072
#> 150: virginica   0.55717174  0.56793014   0.35634832   0.3340766

pobk = po("splines", Boundary.knots = list(
  Petal.Length = c(0, 4), Petal.Width = c(4, 7), Sepal.Length = c(1, 5), Sepal.Width = c(3, 6))
)
pobk$train(list(task))[[1]]$data()
#>        Species Petal.Length Petal.Width Sepal.Length Sepal.Width
#>         <fctr>        <num>       <num>        <num>       <num>
#>   1:    setosa    0.2806243  -1.0155927    0.8218283  0.13363062
#>   2:    setosa    0.2806243  -1.0155927    0.7817391  0.00000000
#>   3:    setosa    0.2605797  -1.0155927    0.7416499  0.05345225
#>   4:    setosa    0.3006689  -1.0155927    0.7216054  0.02672612
#>   5:    setosa    0.2806243  -1.0155927    0.8017837  0.16035675
#>  ---                                                            
#> 146: virginica    1.0423188  -0.4543441    1.1425418  0.00000000
#> 147: virginica    1.0022297  -0.5612486    1.0623634 -0.13363062
#> 148: virginica    1.0423188  -0.5345225    1.1024526  0.00000000
#> 149: virginica    1.0824080  -0.4543441    1.0423188  0.10690450
#> 150: virginica    1.0222743  -0.5879747    0.9821851  0.00000000