SlideShare a Scribd company logo
1 of 6
Download to read offline
R:


     sesejun@is.ocha.ac.jp
          2010/11/04
> 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

More Related Content

What's hot

PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arraysKumar
 
第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 DatasourceKaz Watanabe
 
Using arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationUsing arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationNicole Ryan
 
12 Mini Lesson - Better Truncate
12 Mini Lesson - Better Truncate12 Mini Lesson - Better Truncate
12 Mini Lesson - Better TruncateConnor McDonald
 
Getting to know Arel
Getting to know ArelGetting to know Arel
Getting to know ArelRay Zane
 

What's hot (8)

Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
php plus mysql
php plus mysqlphp plus mysql
php plus mysql
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
 
第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource第49回Php勉強会@関東 Datasource
第49回Php勉強会@関東 Datasource
 
Using arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationUsing arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing information
 
12 Mini Lesson - Better Truncate
12 Mini Lesson - Better Truncate12 Mini Lesson - Better Truncate
12 Mini Lesson - Better Truncate
 
Getting to know Arel
Getting to know ArelGetting to know Arel
Getting to know Arel
 

Similar to 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
 
Data Pipelines in Swift
Data Pipelines in SwiftData Pipelines in Swift
Data Pipelines in SwiftJason Larsen
 
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
 
TAO Fayan_Report on Top 10 data mining algorithms applications with R
TAO Fayan_Report on Top 10 data mining algorithms applications with RTAO Fayan_Report on Top 10 data mining algorithms applications with R
TAO Fayan_Report on Top 10 data mining algorithms applications with RFayan TAO
 

Similar to 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
 
Session 02
Session 02Session 02
Session 02
 
Data Pipelines in Swift
Data Pipelines in SwiftData Pipelines in Swift
Data Pipelines in Swift
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
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
 
TAO Fayan_Report on Top 10 data mining algorithms applications with R
TAO Fayan_Report on Top 10 data mining algorithms applications with RTAO Fayan_Report on Top 10 data mining algorithms applications with R
TAO Fayan_Report on Top 10 data mining algorithms applications with R
 

More from 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
 
100401 Bioinfoinfra
100401 Bioinfoinfra100401 Bioinfoinfra
100401 Bioinfoinfrasesejun
 
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
 

More from 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
 
100401 Bioinfoinfra
100401 Bioinfoinfra100401 Bioinfoinfra
100401 Bioinfoinfra
 
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 r 3rd

  • 1. R: sesejun@is.ocha.ac.jp 2010/11/04
  • 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