LoginSignup
0
4

More than 5 years have passed since last update.

[memo]決定木を出して、summary出しつつ、可視化もする

Last updated at Posted at 2017-05-12

よく使う設定なのでここに記録

data %>>% (rpart(y~x_1+x_2+x_3, ., method="class", cp=.0000001, maxdepth=4)) %>>% (~ plot(., uniform=T, margin=.1)) %>>% (~ text(., use.n=T, all=T, digits=5)) %>>% (summary(.))

  • %>>% パイプ処理。 package pipeRを入れとくと使える
  • rpart:決定木を出してくれる君
    • y~x_1+x_2+x_3yが結果変数、x_iが説明変数
    • method="class"yの値の分類を目的とするときはmethodclassに。
      • 他には、、、
      • anova, poisson, expを指定可能。使ったこと無いので分かりません
    • cp:complexity parameterの略。小さいほど、深い決定木を出してくれる
    • maxdepth:深さの上限を設定。
      • cpを小さくしてmaxdepthで調整という暴力が安易で良い(よくない)
  • plot.rpart
    • uniform=T:可視化した時の縦棒の長さを揃えてくれる
      • なんでdefaultはfalseなんだ?
    • margin=.1:こうしないとテキスト書き込んだときに端が切れる。実質おまじない
  • text.rpart:文字列を書き入れる
    • use.n=T:各所に、どの属性に何データ入るかを表示してくれる
    • all=T:決定木の条件分岐の全てに数値を書き込む設定
    • digits:ほっとくと値を丸める。丸めてほしくないときに大きめの値を入れている
0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4