SlideShare ist ein Scribd-Unternehmen logo
1 von 6
R:


     sesejun@is.ocha.ac.jp
          2009/10/28
> options(repos=c(CRAN="http://cran.md.tsukuba.ac.jp/"))
#                  CRAN
> install.packages('e1071')



> library("e1071")




> contacts.train<-read.table("contacts.csv", header=T, sep=",")
> contacts.test<-read.table("contacts_test.csv", header=T, sep=",")
> contacts.prob<-naiveBayes(contacts.train[,-1],contacts.train[,1])

> predict(contacts.prob,contacts.test[,-1])
[1] N P
Levels: N P
> table(predict(contacts.prob,contacts.test[,-1]),contacts.test[,1])

    N P
  N 1 0
  P 0 1


> predict(contacts.prob,contacts.train[,-1])
 [1] P P P P P P N P N P
Levels: N P

> table(predict(contacts.prob,contacts.train[,-1]),contacts.train[,1])

    N P
  N 2 0
  P 4 4
> iris.train<-read.table("iris_train.csv", header=T, sep=",")
> iris.test<-read.table("iris_test.csv", header=T, sep=",")
> iris.prob<-naiveBayes(iris.train[,-5],iris.train[,5])

> iris.prob
Naive Bayes Classifier for Discrete Predictors

Call:
naiveBayes.default(x = iris.train[, -5], y = iris.train[, 5])
A-priori probabilities:
iris.train[, 5]
    Iris-setosa Iris-versicolor Iris-virginica
      0.3583333       0.3416667       0.3000000
Conditional probabilities:
                 Sepal.length
iris.train[, 5]       [,1]      [,2]
  Iris-setosa     5.000000 0.3664502
  Iris-versicolor 5.960976 0.4705731
  Iris-virginica 6.558333 0.6741662

...
> predict(iris.prob,iris.test[,-5])
  [1] Iris-setosa     Iris-setosa     Iris-setosa
  [4] Iris-setosa     Iris-setosa     Iris-setosa
  [7] Iris-setosa     Iris-setosa     Iris-setosa
 [10] Iris-setosa     Iris-setosa     Iris-setosa ...


> table(predict(iris.prob,iris.test[,-5]), iris.test[,5])

                 Iris-setosa Iris-versicolor Iris-virginica
 Iris-setosa              43               0              0
 Iris-versicolor           0              39              3
 Iris-virginica            0               2             33
Datamining R 3rd

Weitere ähnliche Inhalte

Andere mochten auch

Ohp Seijoen H20 09 Sodosei Kensaku
Ohp Seijoen H20 09 Sodosei KensakuOhp Seijoen H20 09 Sodosei Kensaku
Ohp Seijoen H20 09 Sodosei Kensakusesejun
 
100401 Bioinfoinfra
100401 Bioinfoinfra100401 Bioinfoinfra
100401 Bioinfoinfrasesejun
 
Datamining 7th Kmeans
Datamining 7th KmeansDatamining 7th Kmeans
Datamining 7th Kmeanssesejun
 
Linguagens Dinamicas - Tech Days 2008
Linguagens Dinamicas - Tech Days 2008Linguagens Dinamicas - Tech Days 2008
Linguagens Dinamicas - Tech Days 2008Alcides Fonseca
 

Andere mochten auch (8)

080807
080807080807
080807
 
Ohp Seijoen H20 09 Sodosei Kensaku
Ohp Seijoen H20 09 Sodosei KensakuOhp Seijoen H20 09 Sodosei Kensaku
Ohp Seijoen H20 09 Sodosei Kensaku
 
100401 Bioinfoinfra
100401 Bioinfoinfra100401 Bioinfoinfra
100401 Bioinfoinfra
 
Datamining 7th Kmeans
Datamining 7th KmeansDatamining 7th Kmeans
Datamining 7th Kmeans
 
Linguagens Dinamicas - Tech Days 2008
Linguagens Dinamicas - Tech Days 2008Linguagens Dinamicas - Tech Days 2008
Linguagens Dinamicas - Tech Days 2008
 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
 
XMPP - Beyond IM
XMPP - Beyond IMXMPP - Beyond IM
XMPP - Beyond IM
 
Introdução Web
Introdução WebIntrodução Web
Introdução Web
 

Ähnlich wie Datamining R 3rd

Datamining R 4th
Datamining R 4thDatamining R 4th
Datamining R 4thsesejun
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPaweł Dawczak
 
Datamining r 2nd
Datamining r 2ndDatamining r 2nd
Datamining r 2ndsesejun
 
Datamining R 2nd
Datamining R 2ndDatamining R 2nd
Datamining R 2ndsesejun
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007Damien Seguy
 
Data Pipelines in Swift
Data Pipelines in SwiftData Pipelines in Swift
Data Pipelines in SwiftJason Larsen
 

Ähnlich wie Datamining R 3rd (9)

Datamining R 4th
Datamining R 4thDatamining R 4th
Datamining R 4th
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
 
Datamining r 2nd
Datamining r 2ndDatamining r 2nd
Datamining r 2nd
 
Datamining R 2nd
Datamining R 2ndDatamining R 2nd
Datamining R 2nd
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
Session 02
Session 02Session 02
Session 02
 
PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007
 
Data Pipelines in Swift
Data Pipelines in SwiftData Pipelines in Swift
Data Pipelines in Swift
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 

Mehr von sesejun

RNAseqによる変動遺伝子抽出の統計: A Review
RNAseqによる変動遺伝子抽出の統計: A ReviewRNAseqによる変動遺伝子抽出の統計: A Review
RNAseqによる変動遺伝子抽出の統計: A Reviewsesejun
 
バイオインフォマティクスによる遺伝子発現解析
バイオインフォマティクスによる遺伝子発現解析バイオインフォマティクスによる遺伝子発現解析
バイオインフォマティクスによる遺伝子発現解析sesejun
 
次世代シーケンサが求める機械学習
次世代シーケンサが求める機械学習次世代シーケンサが求める機械学習
次世代シーケンサが求める機械学習sesejun
 
20110602labseminar pub
20110602labseminar pub20110602labseminar pub
20110602labseminar pubsesejun
 
20110524zurichngs 2nd pub
20110524zurichngs 2nd pub20110524zurichngs 2nd pub
20110524zurichngs 2nd pubsesejun
 
20110524zurichngs 1st pub
20110524zurichngs 1st pub20110524zurichngs 1st pub
20110524zurichngs 1st pubsesejun
 
20110214nips2010 read
20110214nips2010 read20110214nips2010 read
20110214nips2010 readsesejun
 
Datamining 9th association_rule.key
Datamining 9th association_rule.keyDatamining 9th association_rule.key
Datamining 9th association_rule.keysesejun
 
Datamining 8th hclustering
Datamining 8th hclusteringDatamining 8th hclustering
Datamining 8th hclusteringsesejun
 
Datamining r 4th
Datamining r 4thDatamining r 4th
Datamining r 4thsesejun
 
Datamining r 1st
Datamining r 1stDatamining r 1st
Datamining r 1stsesejun
 
Datamining 6th svm
Datamining 6th svmDatamining 6th svm
Datamining 6th svmsesejun
 
Datamining 5th knn
Datamining 5th knnDatamining 5th knn
Datamining 5th knnsesejun
 
Datamining 4th adaboost
Datamining 4th adaboostDatamining 4th adaboost
Datamining 4th adaboostsesejun
 
Datamining 3rd naivebayes
Datamining 3rd naivebayesDatamining 3rd naivebayes
Datamining 3rd naivebayessesejun
 
Datamining 2nd decisiontree
Datamining 2nd decisiontreeDatamining 2nd decisiontree
Datamining 2nd decisiontreesesejun
 
Datamining 7th kmeans
Datamining 7th kmeansDatamining 7th kmeans
Datamining 7th kmeanssesejun
 
Datamining 8th Hclustering
Datamining 8th HclusteringDatamining 8th Hclustering
Datamining 8th Hclusteringsesejun
 
Datamining 9th Association Rule
Datamining 9th Association RuleDatamining 9th Association Rule
Datamining 9th Association Rulesesejun
 
Datamining 9th Association Rule
Datamining 9th Association RuleDatamining 9th Association Rule
Datamining 9th Association Rulesesejun
 

Mehr von sesejun (20)

RNAseqによる変動遺伝子抽出の統計: A Review
RNAseqによる変動遺伝子抽出の統計: A ReviewRNAseqによる変動遺伝子抽出の統計: A Review
RNAseqによる変動遺伝子抽出の統計: A Review
 
バイオインフォマティクスによる遺伝子発現解析
バイオインフォマティクスによる遺伝子発現解析バイオインフォマティクスによる遺伝子発現解析
バイオインフォマティクスによる遺伝子発現解析
 
次世代シーケンサが求める機械学習
次世代シーケンサが求める機械学習次世代シーケンサが求める機械学習
次世代シーケンサが求める機械学習
 
20110602labseminar pub
20110602labseminar pub20110602labseminar pub
20110602labseminar pub
 
20110524zurichngs 2nd pub
20110524zurichngs 2nd pub20110524zurichngs 2nd pub
20110524zurichngs 2nd pub
 
20110524zurichngs 1st pub
20110524zurichngs 1st pub20110524zurichngs 1st pub
20110524zurichngs 1st pub
 
20110214nips2010 read
20110214nips2010 read20110214nips2010 read
20110214nips2010 read
 
Datamining 9th association_rule.key
Datamining 9th association_rule.keyDatamining 9th association_rule.key
Datamining 9th association_rule.key
 
Datamining 8th hclustering
Datamining 8th hclusteringDatamining 8th hclustering
Datamining 8th hclustering
 
Datamining r 4th
Datamining r 4thDatamining r 4th
Datamining r 4th
 
Datamining r 1st
Datamining r 1stDatamining r 1st
Datamining r 1st
 
Datamining 6th svm
Datamining 6th svmDatamining 6th svm
Datamining 6th svm
 
Datamining 5th knn
Datamining 5th knnDatamining 5th knn
Datamining 5th knn
 
Datamining 4th adaboost
Datamining 4th adaboostDatamining 4th adaboost
Datamining 4th adaboost
 
Datamining 3rd naivebayes
Datamining 3rd naivebayesDatamining 3rd naivebayes
Datamining 3rd naivebayes
 
Datamining 2nd decisiontree
Datamining 2nd decisiontreeDatamining 2nd decisiontree
Datamining 2nd decisiontree
 
Datamining 7th kmeans
Datamining 7th kmeansDatamining 7th kmeans
Datamining 7th kmeans
 
Datamining 8th Hclustering
Datamining 8th HclusteringDatamining 8th Hclustering
Datamining 8th Hclustering
 
Datamining 9th Association Rule
Datamining 9th Association RuleDatamining 9th Association Rule
Datamining 9th Association Rule
 
Datamining 9th Association Rule
Datamining 9th Association RuleDatamining 9th Association Rule
Datamining 9th Association Rule
 

Datamining R 3rd

  • 1. R: sesejun@is.ocha.ac.jp 2009/10/28
  • 2. > options(repos=c(CRAN="http://cran.md.tsukuba.ac.jp/")) # CRAN > install.packages('e1071') > library("e1071") > contacts.train<-read.table("contacts.csv", header=T, sep=",") > contacts.test<-read.table("contacts_test.csv", header=T, sep=",")
  • 3. > contacts.prob<-naiveBayes(contacts.train[,-1],contacts.train[,1]) > predict(contacts.prob,contacts.test[,-1]) [1] N P Levels: N P > table(predict(contacts.prob,contacts.test[,-1]),contacts.test[,1]) N P N 1 0 P 0 1 > predict(contacts.prob,contacts.train[,-1]) [1] P P P P P P N P N P Levels: N P > table(predict(contacts.prob,contacts.train[,-1]),contacts.train[,1]) N P N 2 0 P 4 4
  • 4. > iris.train<-read.table("iris_train.csv", header=T, sep=",") > iris.test<-read.table("iris_test.csv", header=T, sep=",") > iris.prob<-naiveBayes(iris.train[,-5],iris.train[,5]) > iris.prob Naive Bayes Classifier for Discrete Predictors Call: naiveBayes.default(x = iris.train[, -5], y = iris.train[, 5]) A-priori probabilities: iris.train[, 5] Iris-setosa Iris-versicolor Iris-virginica 0.3583333 0.3416667 0.3000000 Conditional probabilities: Sepal.length iris.train[, 5] [,1] [,2] Iris-setosa 5.000000 0.3664502 Iris-versicolor 5.960976 0.4705731 Iris-virginica 6.558333 0.6741662 ...
  • 5. > predict(iris.prob,iris.test[,-5]) [1] Iris-setosa Iris-setosa Iris-setosa [4] Iris-setosa Iris-setosa Iris-setosa [7] Iris-setosa Iris-setosa Iris-setosa [10] Iris-setosa Iris-setosa Iris-setosa ... > table(predict(iris.prob,iris.test[,-5]), iris.test[,5]) Iris-setosa Iris-versicolor Iris-virginica Iris-setosa 43 0 0 Iris-versicolor 0 39 3 Iris-virginica 0 2 33