viralx_knn_shap {viralx}R Documentation

Explain K Nearest Neighbor Model using SHAP values

Description

This function calculates SHAP (SHapley Additive exPlanations) values for a K-Nearest Neighbors (KNN) model trained on HIV data with specified hyperparameters.

Usage

viralx_knn_shap(
  vip_featured,
  hiv_data,
  knn_hyperparameters,
  vip_train,
  vip_new,
  orderings
)

Arguments

vip_featured

The name of the response variable to explain.

hiv_data

The training dataset containing predictor variables and the response variable.

knn_hyperparameters

A list of hyperparameters for the KNN model, including:

  • neighbors: The number of neighbors to consider.

  • weight_func: The weight function to use.

  • dist_power: The distance power parameter.

vip_train

The dataset used for training the KNN model.

vip_new

The dataset for which SHAP values are calculated.

orderings

The number of orderings for SHAP value calculations.

Value

A list of SHAP values for each observation in vip_new.

Examples

## Not run: 
set.seed(123)
hiv_data <- train2
knn_hyperparameters <- list(neighbors = 5, weight_func = "optimal", dist_power = 0.3304783)
vip_featured <- c("cd_2022")
vip_train <- hiv_data
vip_new <- vip_train[1, ]
orderings <- 20
viralx_knn_shap(vip_featured, hiv_data, knn_hyperparameters, vip_train, vip_new, orderings)

## End(Not run)

[Package viralx version 1.3.0 Index]