Confusion Table

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Confusion Table

reichmaj
R-Help

 

R-Help community is there an simple straight forward way  of changing my
confusion table output to list "Yes" before "No" rather than "No" before
"Yes" - R default.

 

# Making predictions on the test set.

tst_pred <- ifelse(predict(model_glm, newdata = default_tst, type =
"response") > 0.5, "Yes", "No")

tst_tab <- table(predicted = tst_pred, actual = default_tst$default)

tst_tab

 

##                    actual

## predicted   No  Yes

##          No  4817  113

##          Yes      18    52

 

Jeff


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Confusion Table

plangfelder
The lazy way is to do

tst_tab = tst_tab[c(2,1), c(2,1)]

The less lazy way is something like

tst_tab <- table(predicted = factor(tst_pred, levels = c("Yes",
"No")),  actual = factor(default_tst$default, levels = c("Yes",
"No")))

Peter

On Wed, Jan 16, 2019 at 4:39 PM <[hidden email]> wrote:

>
> R-Help
>
>
>
> R-Help community is there an simple straight forward way  of changing my
> confusion table output to list "Yes" before "No" rather than "No" before
> "Yes" - R default.
>
>
>
> # Making predictions on the test set.
>
> tst_pred <- ifelse(predict(model_glm, newdata = default_tst, type =
> "response") > 0.5, "Yes", "No")
>
> tst_tab <- table(predicted = tst_pred, actual = default_tst$default)
>
> tst_tab
>
>
>
> ##                    actual
>
> ## predicted   No  Yes
>
> ##          No  4817  113
>
> ##          Yes      18    52
>
>
>
> Jeff
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Confusion Table

Jeff Newmiller
In reply to this post by reichmaj
If you turn your character variable into a factor and specify the levels argument, you can control the sequence in which any discrete values are presented.

tst_pred <- factor( tst_pred, levels=c("No","Yes") )

On January 16, 2019 4:31:15 PM PST, [hidden email] wrote:

>R-Help
>
>
>
>R-Help community is there an simple straight forward way  of changing
>my
>confusion table output to list "Yes" before "No" rather than "No"
>before
>"Yes" - R default.
>
>
>
># Making predictions on the test set.
>
>tst_pred <- ifelse(predict(model_glm, newdata = default_tst, type =
>"response") > 0.5, "Yes", "No")
>
>tst_tab <- table(predicted = tst_pred, actual = default_tst$default)
>
>tst_tab
>
>
>
>##                    actual
>
>## predicted   No  Yes
>
>##          No  4817  113
>
>##          Yes      18    52
>
>
>
>Jeff
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Confusion Table

reichmaj
In reply to this post by plangfelder
That's easy enough

Thanks

-----Original Message-----
From: Peter Langfelder <[hidden email]>
Sent: Wednesday, January 16, 2019 6:48 PM
To: [hidden email]
Cc: r-help <[hidden email]>
Subject: Re: [R] Confusion Table

The lazy way is to do

tst_tab = tst_tab[c(2,1), c(2,1)]

The less lazy way is something like

tst_tab <- table(predicted = factor(tst_pred, levels = c("Yes", "No")),  actual = factor(default_tst$default, levels = c("Yes",
"No")))

Peter

On Wed, Jan 16, 2019 at 4:39 PM <[hidden email]> wrote:

>
> R-Help
>
>
>
> R-Help community is there an simple straight forward way  of changing
> my confusion table output to list "Yes" before "No" rather than "No"
> before "Yes" - R default.
>
>
>
> # Making predictions on the test set.
>
> tst_pred <- ifelse(predict(model_glm, newdata = default_tst, type =
> "response") > 0.5, "Yes", "No")
>
> tst_tab <- table(predicted = tst_pred, actual = default_tst$default)
>
> tst_tab
>
>
>
> ##                    actual
>
> ## predicted   No  Yes
>
> ##          No  4817  113
>
> ##          Yes      18    52
>
>
>
> Jeff
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Confusion Table

reichmaj
In reply to this post by Jeff Newmiller
Ah yes - thank you

-----Original Message-----
From: Jeff Newmiller <[hidden email]>
Sent: Wednesday, January 16, 2019 6:49 PM
To: [hidden email]; [hidden email]
Subject: Re: [R] Confusion Table

If you turn your character variable into a factor and specify the levels argument, you can control the sequence in which any discrete values are presented.

tst_pred <- factor( tst_pred, levels=c("No","Yes") )

On January 16, 2019 4:31:15 PM PST, [hidden email] wrote:

>R-Help
>
>
>
>R-Help community is there an simple straight forward way  of changing
>my confusion table output to list "Yes" before "No" rather than "No"
>before
>"Yes" - R default.
>
>
>
># Making predictions on the test set.
>
>tst_pred <- ifelse(predict(model_glm, newdata = default_tst, type =
>"response") > 0.5, "Yes", "No")
>
>tst_tab <- table(predicted = tst_pred, actual = default_tst$default)
>
>tst_tab
>
>
>
>##                    actual
>
>## predicted   No  Yes
>
>##          No  4817  113
>
>##          Yes      18    52
>
>
>
>Jeff
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.