Upgrade to Pro — share decks privately, control downloads, hide ads and more …

tidy_rpart

bk
January 21, 2023

 tidy_rpart

bk

January 21, 2023
Tweet

More Decks by bk

Other Decks in Programming

Transcript

  1. ʙ broomstickύοέʔδͱtidyrulesύοέʔδ ʙ tidyͳrpart

  2. ໨࣍ 2 ൃදͷ໨త tidymodelsͱ͸ broomύοέʔδͰϞσϧ࣮ߦ݁ՌΛtidyʹม׵ broomstickύοέʔδͰrpartʹରԠ tidyrulesύοέʔδͰ෼ذ৘ใΛtidyʹม׵ ·ͱΊ ࢀߟจݙ ɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾ

    ɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾ ɾɾɾɾɾɾɾɾɾɾɾɾɾ ɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾ ɾɾɾɾɾɾɾɾɾɾɾ ɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾ ɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾ p.3 p.4-5 p.6-11 p.12-14 p.15-18 p.19 p.20
  3. ൃදͷ໨త 3 ໨త ͋·Γ࿩͞ͳ͍͜ͱ • rpartΦϒδΣΫτͷtidyͳѻ͍Λ஌Δ • tidymodelsͦͷ΋ͷͷѻ͍ํ

  4. tidymodels

  5. tidymodelsͱ͸ 5 “tidymodels͸tidyͳ࿮૊ΈͰػցֶशϞσϦϯάΛߦ͏ͨΊͷύοέʔδΛ ෳ਺ूΊͨπʔϧ܈Ͱ͢ɻ” ʰRϢʔβͷͨΊͷtidymodels[࣮ફ]ೖ໳ʙϞμϯͳ౷ܭɾػցֶशϞσϦϯάͷੈքʱ, https://gihyo.jp/book/2023/978-4-297-13236-1

  6. broomύοέʔδ

  7. σʔλͷ४උ 7 rpartύοέʔδͷkyphosisσʔλΛαϯϓϧσʔλͱͯ͠ਐΊΔɻ kyphosis: Data on Children who have had

    Corrective Spinal Surgery in rpart: Recursive Partitioning and Regression Trees, https://rdrr.io/cran/rpart/man/kyphosis.html
  8. broomύοέʔδ 8 broomύοέʔδ͸લॲཧ΍Ϟσϧͷ࣮ߦ݁ՌΛ”tidy data”ʹ੔ܗ͢Δɻ ҎԼͷදʹ͋Δ3ͭͷؔ਺͕ओɻ ؔ਺໊ ࣮ߦ಺༰ tidy()ؔ਺ લॲཧ΍Ϟσϧͷ࣮ߦ݁ՌΛtidyʹ੔ܗ͢Δ augment()ؔ਺

    ֶशσʔλʹ༧ଌ஋ͱ࢒ࠩΛ෇༩͢Δ glance()ؔ਺ Ϟσϧબ୒ʹར༻͢ΔAIC΍ܾఆ܎਺ΛಘΔ
  9. broomύοέʔδ 9 broom::tidy()ؔ਺ͷ࢖༻ྫɻ lm()ؔ਺ͰઢܗճؼϞσϧΛ࣮ߦͯ͠ɺbroom::tidy()ؔ਺Ͱ݁ՌΛtidyʹ͢Δɻ

  10. broomύοέʔδ 10 ࣍ʹɺrpart::rpart()ؔ਺Ͱܾఆ໦ϞσϧΛ࡞੒͢Δɻ

  11. broomύοέʔδ 11 ࣮ߦ݁ՌͰ͋Δfit_rpartʹbroom::tidy()ؔ਺Λద༻͢ΔͱΤϥʔʹͳΔɻ vignetteʹ΋rpartΫϥε͸هࡌ͞Ε͍ͯͳ͍ɻ Available methods, https://cloud.r-project.org/web/packages/broom/vignettes/available-methods.html

  12. broomstickύοέʔδ

  13. broomstickύοέʔδ 13 ܾఆ໦ʹ͸broomstickύοέʔδͱ͍͏΋ͷ͕։ൃ͞Ε͍ͯΔɻ Convert Decision Tree Objects into Tidy Data

    Frames • broomstick, https://broomstick.njtierney.com/
  14. broomstickύοέʔδ 14 broomstick::tidy()ؔ਺Ͱrpartͷ݁Ռ͕tidy dataͰऔಘͰ͖Δɻ 2023೥1݄21೔ݱࡏɺCRANʹొ࿥͞Ε͍ͯͳ͍ͷͰGitHub͔ΒΠϯετʔϧɻ

  15. tidyrulesύοέʔδ

  16. tidyrulesύοέʔδ 16 ෼ذͷ৘ใΛऔಘ͍ͨ͠৔߹ɺ಺෦ม਺ʹΞΫηε͢Δඞཁ͕͋Δɻ partykit/party.R at 06ba66bd8246eca835c67d23f0af95bff9a86c2c · cran/partykit · GitHub,

    https://github.com/cran/partykit/blob/06ba66bd8246eca835c67d23f0af95bff9a86c2c/R/party.R tidyrules/rpart.R at master · talegari/tidyrules · GitHub, https://github.com/talegari/tidyrules/blob/master/R/rpart.R labels.rpart function - RDocumentation, https://www.rdocumentation.org/packages/rpart/versions/4.1.16/topics/labels.rpart
  17. tidyrulesύοέʔδ 17 tidyrulesύοέʔδͷtidyRules()ؔ਺Ͱɺ؆୯ʹ෼ذ৘ใΛऔಘͰ͖Δɻ Obtain Rules from Rule Based Models as

    Tidy Dataframe • tidyrules, https://talegari.github.io/tidyrules/index.html
  18. tidyrulesύοέʔδ 18 tidyRules()ؔ਺͔Βฦ͖֤ͬͯͨม਺ͷ಺༰͸ҎԼͷ௨Γɻ ม਺໊ ಺༰ LHS Rules. RHS Predicted Class.

    support Number of observation covered by the rule. confidence Prediction accuracy for respective class. (laplace correction is implemented by default) lift The result of dividing the rule's estimated accuracy by the relative frequency of the predicted class in the training set. tidyrules/tidyrules_vignette.Rmd at master · talegari/tidyrules · GitHub, https://github.com/talegari/tidyrules/blob/master/vignettes/tidyrules_vignette.Rmd
  19. ·ͱΊ 19 • rpartΦϒδΣΫτ͔Β 
 ɹbroomstickύοέʔδͰม਺ॏཁ౓Λtidyʹऔಘ • rpartΦϒδΣΫτ͔Β 
 ɹtidyrulesύοέʔδͰ෼ذ৘ใͳͲΛtidyʹऔಘ

  20. ࢀߟจݙ 20 • দଜ༏࠸ɼӝੜਅ໵ɼ٢ଜ޿ࢤ, ʰRϢʔβͷͨΊͷtidymodels[࣮ફ]ೖ໳ʙϞμϯͳ౷ܭɾػցֶशϞσϦϯά ͷੈքʱ, https://gihyo.jp/book/2023/978-4-297-13236-1 • kyphosis: Data

    on Children who have had Corrective Spinal Surgery in rpart: Recursive Partitioning and Regression Trees, https:// rdrr.io/cran/rpart/man/kyphosis.html • Available methods, https://cloud.r-project.org/web/packages/broom/vignettes/available-methods.html • Convert Decision Tree Objects into Tidy Data Frames • broomstick, https://broomstick.njtierney.com/ • labels.rpart function - RDocumentation, https://www.rdocumentation.org/packages/rpart/versions/4.1.16/topics/labels.rpart • partykit/party.R at 06ba66bd8246eca835c67d23f0af95bff9a86c2c · cran/partykit · GitHub, https://github.com/cran/partykit/ blob/06ba66bd8246eca835c67d23f0af95bff9a86c2c/R/party.R • tidyrules/rpart.R at master · talegari/tidyrules · GitHub, https://github.com/talegari/tidyrules/blob/master/R/rpart.R • Obtain Rules from Rule Based Models as Tidy Dataframe • tidyrules, https://talegari.github.io/tidyrules/index.html
  21. E n j o y !