Question: Use the matrix function to create the following confusion matrix: USING R > confusion.matrix Computed Accept Computed Reject Accept 540 460 Reject 23460 75540 (2
- Use the matrix function to create the following confusion matrix: USING R
> confusion.matrix
Computed Accept Computed Reject
Accept 540 460
Reject 23460 75540
- (2 Points) Show your code and the matrix that you created.
- (3 Points) Make confusionP (created in Script 3.5 below) a function in your global environment. Using the function, show the number correct, the number incorrect, and the accuracy for the above confusion matrix.
# Script 3.5 Computing Classification Accuracy # This function uses confusion matrix x to determine # model accuracy. confusionP <- function (x) # This function uses confusion matrix x to determine # model accuracy. {correct=0 wrong =0 y<- nrow(x) z<- ncol(x) for (i in 1:y) { for (j in 1:z) if(i==j) correct = correct + x[i,j] else wrong = wrong + x[i,j] } pc <-(round(correct/(correct + wrong)*100,2)) cat(" Correct=", correct," ") cat("Incorrect=", wrong," ")
cat("Accuracy =",pc,"%"," ") }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
