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.prob<-naiveBayes(contacts.train[,-1],contacts.train[,1])> predict(contacts.prob,contacts.test[,-1])[1] N PLevel...
> iris.train<-read.table("iris_train.csv", header=T, sep=",")> iris.test<-read.table("iris_test.csv", header=T, sep=",")> ...
> predict(iris.prob,iris.test[,-5])  [1] Iris-setosa     Iris-setosa     Iris-setosa  [4] Iris-setosa     Iris-setosa     ...
Datamining r 3rd
Upcoming SlideShare
Loading in …5
×

Datamining r 3rd

741 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
741
On SlideShare
0
From Embeds
0
Number of Embeds
62
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Datamining r 3rd

  1. 1. R: sesejun@is.ocha.ac.jp 2010/11/04
  2. 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. 3. > contacts.prob<-naiveBayes(contacts.train[,-1],contacts.train[,1])> predict(contacts.prob,contacts.test[,-1])[1] N PLevels: 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 PLevels: N P> table(predict(contacts.prob,contacts.train[,-1]),contacts.train[,1]) N P N 2 0 P 4 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.probNaive Bayes Classifier for Discrete PredictorsCall: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.3000000Conditional probabilities: Sepal.lengthiris.train[, 5] [,1] [,2] Iris-setosa 5.000000 0.3664502 Iris-versicolor 5.960976 0.4705731 Iris-virginica 6.558333 0.6741662...
  5. 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

×