The SAPP (Sector-adjusted Points Plot) package provides a visualization technique designed to illustrate feature importances and interactions in a two-dimensional space. This method helps users intuitively understand the influence of different features on the model’s predictions by adjusting the position of points according to their associated feature importances.
The calculate_sector_centers() function computes the x
and y coordinates of sector centers based on the provided feature
importances.
Arguments: importances: A numeric
vector of feature importances.
Returns:
A matrix with the x and y coordinates of sector centers.
The adjust_points() function adjusts the position of
points according to the most influential feature for each point.
Arguments:
points: A matrix with original x, y coordinates.
centers: A matrix with x, y coordinates of sector
centers.
importances: A numeric vector of feature
importances.
influence_feature: A vector indicating the most
influential feature for each point.
Returns:
A matrix with new x, y coordinates after adjustment.
The plot_SAPP() function creates a visual representation
of feature influence using ggplot2.
Arguments:
data: A data frame containing the features and target
variable.
importances: A named numeric vector of feature
importances.
influence_feature: A numeric vector indicating the most
influential feature for each point. Returns:
A ggplot2 object representing the SAPP
visualization.
Below is an example demonstrating how to use the SAPP
package with a sample dataset.
install.packages(SA)
# Example Data
set.seed(42)
data <- data.frame(
sex = sample(1:2, 50, replace = TRUE),
num_applications = sample(5:35, 50, replace = TRUE),
work_experience = sample(0:5, 50, replace = TRUE),
education_level = sample(1:5, 50, replace = TRUE),
field_of_study = sample(1:4, 50, replace = TRUE),
age = sample(22:30, 50, replace = TRUE)
)
# Example feature importances
importances <- c(sex = 0.1, num_applications = 0.2, work_experience = 0.3, education_level = 0.25, field_of_study = 0.15)
# Mock influential feature determination
influence_feature <- apply(data[, -ncol(data)], 1, function(x) which.max(x * importances))
# Plot the SAPP
plot_SA(data, importances, influence_feature)The SAPP package is actively being developed. Future
versions may include additional customization options for the
visualizations, support for more types of data, and more advanced
interaction models.
Contributions to the SAPP package are welcome! If you
find a bug or have a feature request, please submit an issue or a pull
request on GitHub.
The SAPP package is licensed under the MIT License.