Skip to content

Instantly share code, notes, and snippets.

@yuu-ito
Last active December 26, 2015 20:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuu-ito/7210665 to your computer and use it in GitHub Desktop.
Save yuu-ito/7210665 to your computer and use it in GitHub Desktop.
mvpart package サンプル

mvpart package サンプル

  • iris(あやめ)の大きな3枚のはなびらは,「Sepal がく片」
  • 小さな3枚のはなびらが,「Petal 花びら」である.
  • Sepal「がく片」の長さと幅・Petal「花びら」の長さと幅
  • Species「あやめ3品種 [setosa・versicolor・virginica]」
data(iris)
d <- iris
names(d) <- tolower(names(d))
summary(d)
##   sepal.length   sepal.width    petal.length   petal.width 
##  Min.   :4.30   Min.   :2.00   Min.   :1.00   Min.   :0.1  
##  1st Qu.:5.10   1st Qu.:2.80   1st Qu.:1.60   1st Qu.:0.3  
##  Median :5.80   Median :3.00   Median :4.35   Median :1.3  
##  Mean   :5.84   Mean   :3.06   Mean   :3.76   Mean   :1.2  
##  3rd Qu.:6.40   3rd Qu.:3.30   3rd Qu.:5.10   3rd Qu.:1.8  
##  Max.   :7.90   Max.   :4.40   Max.   :6.90   Max.   :2.5  
##        species  
##  setosa    :50  
##  versicolor:50  
##  virginica :50  
##                 
##                 
## 
SUMMARY() 意味
Min 最小値
1st Qu 第一四分位数
Median 中央値
Mean 平均値
3rd Qu 第三四分位数
Max 最大値
# install.packages("ggplot2") # インストールしていない場合初回に実行する。
# install.packages("GGally") # インストールしていない場合初回に実行する。
library("ggplot2")
library("GGally")
ggpairs(data = d, color = "species")  # scattar plot, histgram, etc...

plot of chunk mvpart_test

# plot decision tree diagram with using mvpart
# install.packages("mvpart") # インストールしていない場合初回に実行する。
library("mvpart")
d.dtree <- rpart(d, formula = species ~ .)
## plot
plot(d.dtree, uniform = T)
text(d.dtree, use.n = T, uniform = T, cex = 0.7, all = TRUE)

plot of chunk mvpart_test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment