Barnaby
Barnaby

Reputation: 1480

Confusion matrix for a data frame with two predictions

I have a data frame:

Observations<-c(0.23,-0.14,0.12)
Predgreedy<-c(0.25,0.02,-0.05)
Predlinear<-c(-0.02,0.15,0.12)

df1<-data.frame(Observations,Predgreedy,Predlinear)
x_name <- "Observations"
y_name <- "Predgreedy"
z_name <- "Predlinear"
colnames(df1) <- c(x_name, y_name, z_name)

df1
  Observations Predgreedy Predlinear
1         0.23       0.25      -0.02
2        -0.14       0.02       0.15
3         0.12      -0.05       0.12

I would like to create two separate confusion matrix, one for Predgreedy and another for Predlinear in respect to the column of observations (for observations >0 or <0).

Upvotes: 0

Views: 81

Answers (1)

agstudy
agstudy

Reputation: 121608

Are you looking for this?(Better to show the expected output)

table(df1$Observations>0,df1$Predgreedy)

        -0.05 0.02 0.25
  FALSE     0    1    0
  TRUE      1    0    1
table(df1$Observations>0,df1$Predlinear)

        -0.02 0.12 0.15
  FALSE     0    0    1
  TRUE      1    1    0

Upvotes: 1

Related Questions