データサイエンティスト養成読本
データサイエンティスト養成読本
データサイエンティスト養成読本 [ビッグデータ時代のビジネスを支えるデータ分析力が身につく! ] (Software Design plus)
- 作者: 佐藤洋行,原田博植,下田倫大,大成弘子,奥野晃裕,中川帝人,橋本武彦,里洋平,和田計也,早川敦士,倉橋一成
- 出版社/メーカー: 技術評論社
- 発売日: 2013/08/08
- メディア: 大型本
- この商品を含むブログ (12件) を見る
特集1 データ分析実績入門
第1章 Rで統計解析をはじめよう
p.40 まで。
- summary
- glm関数
- ロジスティック回帰モデル
- 決定木モデル
- 説明変数を値や範囲などで分割させて予測や判別のルールを構築するモデル
- 分類木モデル
- 多変量解析:分類
- 主成分分析
- 複数の量的データで表されたデータの類似関係を把握するため、 なるべく情報を落とさずに少ない次元に要約するときに使う手法
- 主成分分析
install.packages("ggplot2") library(ggplot2) # TSVファイル読み込み body.data <- read.table("body_sample.tsv", header=T, stringsAsFactors=F) head(body.data) # CSVファイル読み込み body.data <- read.csv("body_sample.csv", header=T, stringsAsFactors=F) head(body.data) # 数値要約の実行 summary(body.data) # 標準偏差 sd(body.data$height) # 不偏分散 var(body.data$weight) # ヒストグラム ggplot(body.data, aes(x = height)) + geom_histogram() + theme_bw(16) + ylab("count") # ヒストグラム色分け ggplot(body.data, aes(x = height, fill = gender)) + geom_histogram() + theme_bw(16) + ylab("count") # 箱ひげ図 ggplot(body.data, aes(x = gender, y = height, fill = gender)) + geom_boxplot() + theme_bw(16) # 散布図 ggplot(body.data, aes(x = height, y = weight)) + geom_point() + theme_bw(16) # 散布図 + 回帰直線 ggplot(body.data, aes(x = height, y = weight)) + geom_point() + theme_bw(16) + geom_smooth(method = "lm") ggplot(body.data, aes(x = height, y = weight, col = gender)) + geom_point() + theme_bw(16) + geom_smooth(method = "lm") # 相関係数の算出 cor(body.data$height, body.data$weight) body.data.m <- body.data[body.data$gender == "M", ] cor(body.data.m$height, body.data.m$weight) body.data.f <- body.data[body.data$gender == "F", ] cor(body.data.f$height, body.data.f$weight) # 投資と売上データ amount1.data <- read.csv("amount1.csv") head(amount1.data) summary(amount1.data) ggplot(amount1.data, aes(x = invest, y = amount)) + geom_point() + theme_bw(16) # 線形回帰モデルの構築 amount1.lm1 <- lm(amount ~ invest, data = amount1.data) summary(amount1.lm1) # 回帰診断図 plot(amount1.lm1, which = 1) # 逓減型の回帰モデル ggplot(amount1.data, aes(x = invest, y = amount)) + geom_point() + theme_bw(16) + geom_smooth(method = "lm", formula = y ~ log(x)) # 逓減型回帰モデルの構築 amount1.lm2 <- lm(amount ~ log(invest), data = amount1.data) summary(amount1.lm2) plot(amount1.lm2, which = 1) # ロジスティック回帰モデルの構築 z <- data.frame(Titanic) titanic.data <- data.frame( Class = rep(z$Class, z$Freq), Sex = rep(z$Sex, z$Freq), Age= rep(z$Age, z$Freq), Survived = rep(z$Survived, z$Freq) ) titanic.logit <- glm(Survived ~ ., data = titanic.data, family = binomial) summary(titanic.logit) install.packages("epicalc") library(epicalc) logistic.display(titanic.logit, simplified = T) # 決定木モデルの構築 install.packages("rpart") install.packages("partykit") library(rpart) library(partykit) titanic.rp <- rpart(Survived ~ ., data = titanic.data) plot(as.party(titanic.rp), tp_args = T) # 主成分分析の実行 state.pca <- prcomp(state.x77[, 1:6], scale = T) biplot(state.pca)
作成した画像をいくつか。