how to make confusion matrix in r

# Example data
actual <- c("A", "B", "A", "A", "B", "B")
predicted <- c("A", "B", "A", "B", "A", "B")

# Create confusion matrix
conf_matrix <- table(actual, predicted)
print(conf_matrix)
  1. First, create example data for the actual and predicted values. In this case, actual contains the true class labels, and predicted contains the predicted class labels.

  2. Use the table() function in R to generate the confusion matrix. Provide the actual and predicted data as arguments to the table() function.

  3. Assign the resulting confusion matrix to a variable, conf_matrix.

  4. Finally, print the conf_matrix to display the confusion matrix generated based on the provided actual and predicted values.