SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
大事な話は他の人に譲ってReproducible Researchの話
2013/09/06
Data Scientist Casual Talk in 白金台
和田 計也
サイバー系
2013/09/06
はじめに
※この発表は個人の見
解であり、所属する組
織の公式見解ではあり
ません。
サイバー系
2
2013/09/06
u和田 計也(@wdkz)
u 静岡県袋井市出身
uサイバー系企業でデータマイニングエンジニア職
u 最近はJUDY AND MARYばっか聴いてます
u前職はバイオベンチャー
u バイオマーカ探索してた
u 学生時代は枯草菌の研究
自己紹介
サイバー系
3
2013/09/06
いきなりですが
サイバー系
u祝!出版!!
4
u 具体的な事例が豊富
u 入門用として最適
u コナンの正体は工藤新一
2013/09/06
Reproducible Research意識してますか?
サイバー系
u 再利用・再現可能な分析のこと
u ➡こんな経験ありませんか?
✦ データ取得どうやったっけ??
✦ SQL忘れたー
✦ モデリングに突っ込むデータフレームどう作ったっけ?
✦ プロット図どうやって描いたっけ??
u 全部時間の無駄です
u はい、今日からknitr使いましょう
5
2013/09/06
やり方はとても簡単
サイバー系
6
R Studioでごく普通にコーディングして 押す
2013/09/06
やり方はとても簡単
サイバー系
7
何か出るけど気にせず「Compile」ボタン押す
2013/09/06
はい、できました
サイバー系
8
u R使って分析するなら今日から早速knitr使いましょう
u markdown形式で記述できるRmdもありますよ(数式
とかも描ける) http://rpubs.com/wdkz/8129
ソースコードと
実行結果が一体
となったhtmlフ
ァイルが生成さ
れた!!
2013/09/06
サイバー系
9
前置きは
このくらい
にして
2013/09/06
(今日の本題)RHadoopについて
サイバー系
u RからHadoop使えるパッケージ群
u 以下の3つのパッケージからなる
• rmr2・・・Rから簡単にMap Reduce使える
• rhdfs・・・Rからhdfsへの読み書きができる
• rhbase・・・RからHBaseへの読み書きができる
u Revolution R 作ってるRevolutionAnalytics社が作ってる
u https://github.com/RevolutionAnalytics/RHadoop/wiki
10
今日はこれの話
2013/09/06
rmr2パッケージ使ってみるか
サイバー系
u rmr2パッケージ使って、RからHadoopのMap Reduce使う
u Map Reduce版のthe Worldといえばword count
u toy data はPubmedからちょっくら取得
11
➡Pubmed(医療系のジャーナル検索サイト)
2013/09/06
toy dataの取得用関数(参考)
サイバー系
12
library(RCurl)
library(XML)
#検索ワードからpmidを取得
get.pmid <- function(term="wada+kazuya[author]"){
url.str <- paste0("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?
db=pubmed&term=", term)
xml1 <- xmlTreeParse(getURL(url.str))
pmids.list <- xml1[["doc"]][["eSearchResult"]][["IdList"]]
pmids <- rep(NA, length=length(pmids.list))
for(i in 1:length(pmids.list)){
pmids[i] <- as.integer(xmlValue(pmids.list[[i]]))
}
return(pmids)
}
#pmidから論文のAbstructを取得
get.pmsummary <- function(pmids=c(21799770,21416533)){
url.str <- paste0("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?
db=pubmed&id=", paste(pmids, collapse=","), "&retmode=xml")
xml1 <- xmlTreeParse(getURL(url.str))
pm.summaries <- xml1[["doc"]][["PubmedArticleSet"]]
pmsummary <- rep(NA, length=length(pm.summaries))
for(i in 1:length(pm.summaries)){
pmsummary[i] <- xmlValue(pm.summaries[[i]][[1]][["Article"]][["Abstract"]]
[["AbstractText"]])
}
return(pmsummary)
}
pmsummary <- get.pmsummary(get.pmid("wada+kazuya[author]")) #wdkzの論文サマリ取得
2013/09/06
toy dataの中身とhdfsへの転送
サイバー系
13
こんな感じで、取得できた論文数の長さの文字列ベクトル
★ローカルのRオブジェクトをhdfs上に送る
★toy dataの取得
★hdfs上のパス
2013/09/06
hdfs上でのdataの中身
サイバー系
14
こんな感じでkey-value型になっているが、
to.dfs()で転送した場合は大抵keyはNULL
★中身
2013/09/06
Mapフェーズ
サイバー系
15
こんな感じで文字列ベクトルvをpatternで
分割して単語にし、その単語をkey, 1(単語出現
数)をvalueとするkey-valueを構成する
★Mapの関数定義
NULL
文章(文字列ベクトル)
★Map関数適用後にできるもの・・・以下のようなリスト
Key
Value
2013/09/06
Reduceフェーズ
サイバー系
16
こんな感じでkey(単語)ごとにgroup byして、
1をsumするから、最終的に文字数が出るよ
★Reduceの関数定義
単語
1(カウント)
★Reduce関数適用後にできるもの・・・以下のようなリスト
Key
Value
2013/09/06
Map Reduce発動
サイバー系
17
★Map Reduceの関数定義
map関数 reduce関数hdfs上の入力
ファイル
こんな感じでMap Reduce処理を発動させる。
戻り値はhdfs上のパスだが、上記の例のように戻
り値を変数に保存してない場合は以下のようにすれ
ば大丈夫
2013/09/06
結果
サイバー系
18
★結果の整形
蟹好きだということがわかった
2013/09/06
サイバー系
19
(中途半端な)
応用事例
2013/09/06
Hadoop上で動かすrandomForest
サイバー系
20
★randomForest on Map-Reduce概要_モデル構築
train
model
Map Reduce
2013/09/06
Hadoop上で動かすrandomForest
サイバー系
21
★randomForest on Map-Reduce概要_予測
test
Map Reduce
2013/09/06
簡易実装例_model構築
サイバー系
22
wadandomForest <- function(formula, data, ndiv=10,...){�
data.hdfs <- to.dfs(data) # hdfs
# _Maper ndiv
map.fun <- function(k, v){�
generate.rand <- function(i){�
draws <- rpois(n=nrow(v), lambda=(1/ndiv))�
indices <- rep((1:nrow(v)), draws)�
keyval(i, v[indices, ])�
}�
c.keyval(lapply(1:ndiv, generate.rand))�
}�
# _Reducer randomForest hdfs
reduce.fun <- function(k, v){�
rf_mdl <- randomForest::randomForest(formula=formula, data=v, ...)�
keyval(k, list(forest=rf_mdl))�
}�
#Map-Reduce
mr_res <- mapreduce(input=data.hdfs, map=map.fun, reduce=reduce.fun)�
}�
2013/09/06
簡易実装例_変数重要度
サイバー系
23
variableImp <- function(wf_mdl, var_output=NULL){�
#variableImportace Mapper
# key, MeanDecreaseGini value
map.fun <- function(k, v){�
mk.keyval <- function(i){�
keyval(key=rownames(v[[i]]$importance), val=as.numeric(v[[i]]$importance))�
}�
c.keyval(lapply(1:length(k), mk.keyval))�
}�
#variableImportance reduce
reduce.fun <- function(k, v){�
keyval(k, mean(v))�
}�
#MR
mr_res <- mapreduce(input=wf_mdl$model_output, map=map.fun, reduce=reduce.f
}�
variableImp.plot <- function(vi_df=as.data.frame(varImportance)){�
library(ggplot2)�
print(ggplot(vi_df, aes(x=key, y=val)) + geom_bar(stat="identity") �
���������+ opts(axis.text.x=theme_text(angle=-90)))�
}�
2013/09/06
簡易実装例_予測
サイバー系
24
predict.wadandomForest <- function(wf_mdl, data, ...){ �
data.hdfs <- to.dfs(data)�
#predict Mapper
map.fun <- function(k, v){�
generate.rnd <- function(i){�
draws <- rpois(n=nrow(v), lambda=0.2)�
indices <- rep((1:nrow(v)), draws)�
vv <- v[unique(indices), ]�
rf_mdl <- rf_mdls$val[[sample(length(rf_mdls$key),1)]]�
vv_prd <- predict(rf_mdl, vv, …)�
keyval(as.integer(names(vv_prd)), as.integer(vv_prd))�
}�
library(randomForest)�
rf_mdls <- from.dfs(wf_mdl$model_output)�
c.keyval(lapply(1:100, generate.rnd)) �
}
#predict reduce
reduce.fun <- function(k, v){�
keyval(k, mean(v))�
}�
#MR
mr_res <- mapreduce(input=data.hdfs, map=map.fun, reduce=reduce.fun)�
} �
2013/09/06
randomForest on Hadoop実行結果例
サイバー系
25
★randomForest on Map-Reduce概要_予測
�������������1 ���� 2�
1 45576 1664�
2 ��3893 5824�
#model hdfs
wf_mdl <- wadandomForest(formula=label ~ ., data=train.data)�
#
wf_varImp <- variableImp(wf_mdl)�
varImportance <- from.dfs(wf_varImp)�
variableImp.plot(as.data.frame(varImportance))�
#
wf_pred <- predict.wadandomForest(wf_mdl, test.data)�
wf_result <- from.dfs(wf_pred)�
#
table(as.integer(gf_test$label), ifelse(wf_result$val>=1.5,2,1))�
2013/09/06
待望のRevolution R Enterprise 7
サイバー系
26
2013/09/06
最後に
サイバー系
•Reproducible Research意識して下さい
•R(RStudio)なら追加コスト追加工数なしで
簡単に実現できます
•RHadoop
•今後のRevolution R Enterprise7
のリリースに期待
•MahoutのrandomForest
(DecisionForest)でちゃんとスケールして
大きなデータを動かせた人いましたら教えて下さい
27

Weitere ähnliche Inhalte

Andere mochten auch

d3jsハンズオン @E2D3ハッカソン
d3jsハンズオン @E2D3ハッカソンd3jsハンズオン @E2D3ハッカソン
d3jsハンズオン @E2D3ハッカソン圭輔 大曽根
 
DeployR使ってみた話
DeployR使ってみた話DeployR使ってみた話
DeployR使ってみた話Kazuya Wada
 
Amebaにおけるレコメンデーションシステムの紹介
Amebaにおけるレコメンデーションシステムの紹介Amebaにおけるレコメンデーションシステムの紹介
Amebaにおけるレコメンデーションシステムの紹介cyberagent
 
Estimating the effect of advertising with Machine learning
Estimating the effect of advertising with Machine learningEstimating the effect of advertising with Machine learning
Estimating the effect of advertising with Machine learningShota Yasui
 
そろそろRStudioの話
そろそろRStudioの話そろそろRStudioの話
そろそろRStudioの話Kazuya Wada
 
論文紹介 Explaining the prevalence, scaling and variance of urban phenomena
論文紹介 Explaining the prevalence, scaling and variance of urban phenomena論文紹介 Explaining the prevalence, scaling and variance of urban phenomena
論文紹介 Explaining the prevalence, scaling and variance of urban phenomenaMasanori Takano
 
ハイレゾの話
ハイレゾの話ハイレゾの話
ハイレゾの話Kazuya Wada
 
はじめてのShiny
はじめてのShinyはじめてのShiny
はじめてのShinyKazuya Wada
 
野良ビッグデータへのお誘い
野良ビッグデータへのお誘い野良ビッグデータへのお誘い
野良ビッグデータへのお誘いMasanori Takano
 

Andere mochten auch (9)

d3jsハンズオン @E2D3ハッカソン
d3jsハンズオン @E2D3ハッカソンd3jsハンズオン @E2D3ハッカソン
d3jsハンズオン @E2D3ハッカソン
 
DeployR使ってみた話
DeployR使ってみた話DeployR使ってみた話
DeployR使ってみた話
 
Amebaにおけるレコメンデーションシステムの紹介
Amebaにおけるレコメンデーションシステムの紹介Amebaにおけるレコメンデーションシステムの紹介
Amebaにおけるレコメンデーションシステムの紹介
 
Estimating the effect of advertising with Machine learning
Estimating the effect of advertising with Machine learningEstimating the effect of advertising with Machine learning
Estimating the effect of advertising with Machine learning
 
そろそろRStudioの話
そろそろRStudioの話そろそろRStudioの話
そろそろRStudioの話
 
論文紹介 Explaining the prevalence, scaling and variance of urban phenomena
論文紹介 Explaining the prevalence, scaling and variance of urban phenomena論文紹介 Explaining the prevalence, scaling and variance of urban phenomena
論文紹介 Explaining the prevalence, scaling and variance of urban phenomena
 
ハイレゾの話
ハイレゾの話ハイレゾの話
ハイレゾの話
 
はじめてのShiny
はじめてのShinyはじめてのShiny
はじめてのShiny
 
野良ビッグデータへのお誘い
野良ビッグデータへのお誘い野良ビッグデータへのお誘い
野良ビッグデータへのお誘い
 

Mehr von Kazuya Wada

Rで触れる日本経済~RでVAR編~
Rで触れる日本経済~RでVAR編~Rで触れる日本経済~RでVAR編~
Rで触れる日本経済~RでVAR編~Kazuya Wada
 
RのffでGLMしてみたけど...
RのffでGLMしてみたけど...RのffでGLMしてみたけど...
RのffでGLMしてみたけど...Kazuya Wada
 
RでつくるWebアプリ~rApache編~
RでつくるWebアプリ~rApache編~RでつくるWebアプリ~rApache編~
RでつくるWebアプリ~rApache編~Kazuya Wada
 
Rでウォーリを探してみた
Rでウォーリを探してみたRでウォーリを探してみた
Rでウォーリを探してみたKazuya Wada
 
Rが苦手な人にもRを使って頂くために~RcommanderとRook~
Rが苦手な人にもRを使って頂くために~RcommanderとRook~Rが苦手な人にもRを使って頂くために~RcommanderとRook~
Rが苦手な人にもRを使って頂くために~RcommanderとRook~Kazuya Wada
 
RのffとbigmemoryとRevoScaleRとを比較してみた
RのffとbigmemoryとRevoScaleRとを比較してみたRのffとbigmemoryとRevoScaleRとを比較してみた
RのffとbigmemoryとRevoScaleRとを比較してみたKazuya Wada
 
RでGPU使ってみた
RでGPU使ってみたRでGPU使ってみた
RでGPU使ってみたKazuya Wada
 

Mehr von Kazuya Wada (8)

Rで触れる日本経済~RでVAR編~
Rで触れる日本経済~RでVAR編~Rで触れる日本経済~RでVAR編~
Rで触れる日本経済~RでVAR編~
 
RのffでGLMしてみたけど...
RのffでGLMしてみたけど...RのffでGLMしてみたけど...
RのffでGLMしてみたけど...
 
RでつくるWebアプリ~rApache編~
RでつくるWebアプリ~rApache編~RでつくるWebアプリ~rApache編~
RでつくるWebアプリ~rApache編~
 
Rでウォーリを探してみた
Rでウォーリを探してみたRでウォーリを探してみた
Rでウォーリを探してみた
 
Rが苦手な人にもRを使って頂くために~RcommanderとRook~
Rが苦手な人にもRを使って頂くために~RcommanderとRook~Rが苦手な人にもRを使って頂くために~RcommanderとRook~
Rが苦手な人にもRを使って頂くために~RcommanderとRook~
 
RのffとbigmemoryとRevoScaleRとを比較してみた
RのffとbigmemoryとRevoScaleRとを比較してみたRのffとbigmemoryとRevoScaleRとを比較してみた
RのffとbigmemoryとRevoScaleRとを比較してみた
 
RでGPU使ってみた
RでGPU使ってみたRでGPU使ってみた
RでGPU使ってみた
 
Tokyo.R#16 wdkz
Tokyo.R#16 wdkzTokyo.R#16 wdkz
Tokyo.R#16 wdkz
 

Kürzlich hochgeladen

Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...oganekyokoi
 
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhrKARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhrRodolfFernandez1
 
Divorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdfDivorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdfoganekyokoi
 
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...yutakashikano1984
 
Establishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdfEstablishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdfoganekyokoi
 
What I did before opening my business..pdf
What I did before opening my business..pdfWhat I did before opening my business..pdf
What I did before opening my business..pdfoganekyokoi
 
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイントshu1108hina1020
 
International Politics I - Lecture 1
International Politics I - Lecture 1International Politics I - Lecture 1
International Politics I - Lecture 1Toru Oga
 

Kürzlich hochgeladen (8)

Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...
 
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhrKARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
 
Divorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdfDivorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdf
 
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
 
Establishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdfEstablishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdf
 
What I did before opening my business..pdf
What I did before opening my business..pdfWhat I did before opening my business..pdf
What I did before opening my business..pdf
 
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
 
International Politics I - Lecture 1
International Politics I - Lecture 1International Politics I - Lecture 1
International Politics I - Lecture 1
 

データサイエンティストカジュアルトーク by wdkz