| KnockoffSampler | R Documentation |
Implements conditional sampling using Knockoffs.
The KnockoffSampler samples Knockoffs based on the task data.
This class allows arbitrary knockoff_fun, which also means that no input checking
against supported feature types can be done. Use KnockoffGaussianSampler for the
Gaussian knockoff sampler for numeric features.
Alternative knockoff samplers include knockoff_seq() from the seqknockoff package
available on GitHub: https://github.com/kormama1/seqknockoff.
Knockoffs are related to the ConditionalSampler familty, with key differences:
They do not allow specifying a conditioning_set
xplainfi::FeatureSampler -> KnockoffSampler
x_tildeKnockoff matrix with one (or iters) row(s) per original observation in task.
new()Creates a new instance of the KnockoffSampler class.
KnockoffSampler$new( task, knockoff_fun = function(x) knockoff::create.second_order(as.matrix(x)), iters = 1 )
task(mlr3::Task) Task to sample from
knockoff_fun(function) Function used to create knockoff matrix. Default are second-order Gaussian knockoffs (knockoff::create.second_order())
iters(integer(1): 1) Number of repetitions the knockoff_fun is applied to create multiple x_tilde
instances per observation.
sample()Sample from stored task using knockoff values. Replaces specified feature(s) with their knockoff counterparts from the pre-generated knockoff matrix.
KnockoffSampler$sample(feature, row_ids = NULL)
feature(character) Feature(s) to sample.
row_ids(integer() | NULL) Row IDs to use. If NULL, uses all rows.
Modified copy with knockoff feature(s).
clone()The objects of this class are cloneable with this method.
KnockoffSampler$clone(deep = FALSE)
deepWhether to make a deep clone.
Watson D, Wright M (2021). “Testing Conditional Independence in Supervised Learning Algorithms.” Machine Learning, 110(8), 2107–2129. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/s10994-021-06030-6")}.
Blesch K, Watson D, Wright M (2023). “Conditional Feature Importance for Mixed Data.” AStA Advances in Statistical Analysis, 108(2), 259–278. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/s10182-023-00477-9")}.
library(mlr3)
task = tgen("2dnormals")$generate(n = 100)
# Create sampler with default parameters
sampler = KnockoffSampler$new(task)
# Sample using row_ids from stored task
sampled_data = sampler$sample("x1")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.