Weitere ähnliche Inhalte
Ähnlich wie Datamining R 3rd
Ähnlich wie Datamining R 3rd (9)
Datamining R 3rd
- 1. R:
sesejun@is.ocha.ac.jp
2009/10/28
- 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