plotModelScore: Plot Model Performance Scores

View source: R/global.visu.R

plotModelScoreR Documentation

Plot Model Performance Scores

Description

This function visualizes the performance of a model by plotting the predicted scores ('yhat') against the true class labels ('y'). It supports both classification (AUC, accuracy) and regression (R2, correlation) tasks. For classification tasks, it displays a boxplot with jittered points, while for regression tasks, it shows a scatter plot with a linear regression line.

Usage

plotModelScore(
  mod = NULL,
  y = NULL,
  col.sign = c("deepskyblue1", "firebrick1"),
  main = ""
)

Arguments

mod

A model object containing the attribute 'score_' (predicted scores) and other model evaluation metrics such as accuracy, AUC, R2, etc.

y

A vector of true class labels or continuous values, corresponding to the predicted scores in 'mod$score_'.

col.sign

A vector of two colors for positive and negative class labels (default is 'c("deepskyblue1", "firebrick1")').

main

A string for the title of the plot (default is an empty string).

Details

This function checks the validity of the model and the input data, then creates a plot based on the model's prediction performance. For classification tasks, it uses a boxplot to show the distribution of predicted scores, while for regression tasks, it uses a scatter plot with a linear regression line.

The function also displays performance metrics in the plot title, such as accuracy and AUC for classification tasks, or correlation coefficient (Rho), R-squared (R2), and standard error of regression (SER) for regression tasks.

If the model is of type 'SOTA' or lacks the required attributes ('score_', 'y'), the function will return 'NULL' and display a corresponding error message.

Value

A ‘ggplot' object displaying the model’s performance plot, either a boxplot for classification tasks or a scatter plot with a regression line for regression tasks.

Author(s)

Edi Prifti (IRD)

Examples

# Example usage for a classification model
model <- train(logistic_regression_model)  # Assume this is a pre-trained model
X <- data.frame(feature1 = rnorm(100), feature2 = rnorm(100))
y <- sample(c(1, -1), 100, replace = TRUE)

# Plot the model's performance score
plotModelScore(model, y, main = "Classification Model Performance")

# Example usage for a regression model
model <- train(regression_model)  # Assume this is a pre-trained model
y <- rnorm(100)  # Continuous response variable

# Plot the model's performance score
plotModelScore(model, y, main = "Regression Model Performance")


predomics/predomicspkg documentation built on Dec. 11, 2024, 11:06 a.m.