Skip to contents

Implements marginal sampling for PFI, where the feature of interest is sampled independently of other features

Super class

xplainfi::FeatureSampler -> MarginalSampler

Methods

Inherited methods


Method new()

Creates a new instance of the MarginalSampler class

Usage

MarginalSampler$new(task)

Arguments

task

(mlr3::Task) Task to sample from


Method sample()

Sample from stored task by permutation (marginal distribution).

Usage

MarginalSampler$sample(feature, row_ids = NULL)

Arguments

feature

(character) Feature(s) to sample.

row_ids

(integer() | NULL) Row IDs to use. If NULL, uses all rows.

Returns

Modified copy with permuted feature(s).


Method sample_newdata()

Sample from external data by permutation. See $sample() for details.

Usage

MarginalSampler$sample_newdata(feature, newdata)

Arguments

feature

(character) Feature(s) to sample.

newdata

(data.table) External data to use.

Returns

Modified copy with permuted feature(s).


Method clone()

The objects of this class are cloneable with this method.

Usage

MarginalSampler$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

library(mlr3)
task = tgen("2dnormals")$generate(n = 100)
sampler = MarginalSampler$new(task)
# Sample using row_ids from stored task
sampled_data = sampler$sample("x1")
# Or use external data
data = task$data()
sampled_data_ext = sampler$sample_newdata("x1", newdata = data)