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)
First, create example data for the actual and predicted values. In this case,
actual
contains the true class labels, andpredicted
contains the predicted class labels.Use the
table()
function in R to generate the confusion matrix. Provide theactual
andpredicted
data as arguments to thetable()
function.Assign the resulting confusion matrix to a variable,
conf_matrix
.Finally, print the
conf_matrix
to display the confusion matrix generated based on the provided actual and predicted values.