#' Read CSV file
#' @param inp data file
#' @export
#' @importFrom utils read.csv
#'
input_data <- function(inp){
read.csv(inp)
}
#' create a list
#' @param i input for function
#' @export
#'
list_fn <- function(i){
list(i)
}
#' Create dictionary
#' @param values input
#' @export
#' @importFrom reticulate py_dict
#'
dict_fn <- function(values){
c(py_dict(c(values[[1]]),c(values[[2]]), convert = FALSE))
}
#' Function to create AIF compatible dataset
#' @param data_path Path to the input CSV file
#' @param favor_label Value of the label which is considered to be favorable
#' @param unfavor_label Value of the label which is considered to be unfavorable
#' @param unprivileged_protected_attribute Vector containing attribute label name and value
#' @param target_column Column label name
#' @param protected_attribute label name of the protected attribute
#' @export
#' @importFrom reticulate py_suppress_warnings py_dict
#'
aif_dataset <- function(data_path, favor_label,
unfavor_label, unprivileged_protected_attribute,
target_column, protected_attribute) {
dataframe <- input_data(data_path)
unprivileged_protected_dict <- dict_fn(unprivileged_protected_attribute)
target_column_list <- list_fn(target_column)
protected_attribute_list <- list_fn(protected_attribute)
return(datasets$BinaryLabelDataset(df = dataframe,
favorable_label = favor_label,
unfavorable_label = unfavor_label,
unprivileged_protected_attributes = unprivileged_protected_dict,
label_names = target_column_list,
protected_attribute_names = protected_attribute_list))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.