View source: R/add_noise_cat_unif.R
| add_noise_cat_unif | R Documentation |
Inject noise into a categorical random variable by mixing a sample of uniform records into the predictions.
add_noise_cat_unif(
model,
new_data,
conf_model_data,
outcome_var,
col_schema,
pred,
unif_prop,
resample_props = NULL,
observed_levels = FALSE
)
model |
A |
new_data |
A data frame used to generate predictions |
conf_model_data |
A data frame for estimating the predictive model |
outcome_var |
A string name representing the outcome variable |
col_schema |
A list of column schema specifications for the new variable |
pred |
A vector of values predicted by the model |
unif_prop |
A proportion of records to resample with uniform noise |
resample_props |
An optional named vector of probabilities for resampling,
defaults to uniform over all levels supplied in |
observed_levels |
An optional Boolean to only resample from observed levels in the confidential data. |
A numeric vector with noise added to each prediction
conf_model_data <- mtcars|>
dplyr::mutate(gear = factor(.data[["gear"]]))
col_schema <- list(
"dtype" = "fct",
"levels" = c("3", "4", "5"),
"na_prop" = 0
)
add_noise_cat_unif(
model = conf_model_data,
new_data = NULL,
conf_model_data = NULL,
outcome_var = "gear",
col_schema = col_schema,
pred = factor(c(rep("3", 10), rep("4", 10), rep("5", 10))),
unif_prop = 0.5
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.