0
Ich versuche, eine Klassifizierung mit NaiveBayes mit Iris DataSet mit e1071-Paket zu tun, und es stellt sich heraus, dass ich die Vorhersage nicht wie in Rpart machen kann. Wie kann ich das lösen, damit ich eine Verwirrungsmatrix basierend auf p4 erstellen kann, die ich vorherzusagen versuche?NaiveBayes in R kann nicht vorhersagen
> table(iris$Species)
setosa versicolor virginica
50 50 50
> head(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
> set.seed(9850)
> g<-runif(nrow(iris))
> irisr <- iris[order(g),]
> m4 <- naiveBayes(Species~., data=irisr[1:100,], method="class")
> m4
Naive Bayes Classifier for Discrete Predictors
Call:
naiveBayes.default(x = X, y = Y, laplace = laplace, method = "class")
A-priori probabilities:
Y
setosa versicolor virginica
0.34 0.35 0.31
Conditional probabilities:
Sepal.Length
Y [,1] [,2]
setosa 5.000000 0.3797926
versicolor 5.857143 0.4545752
virginica 6.658065 0.7017949
Sepal.Width
Y [,1] [,2]
setosa 3.461765 0.4221264
versicolor 2.717143 0.3212894
virginica 2.990323 0.3543584
Petal.Length
Y [,1] [,2]
setosa 1.450000 0.1619016
versicolor 4.197143 0.4273624
virginica 5.600000 0.6066300
Petal.Width
Y [,1] [,2]
setosa 0.2558824 0.1159707
versicolor 1.2800000 0.1827889
virginica 2.0000000 0.2708013
> summary (m4)
Length Class Mode
apriori 3 table numeric
tables 4 -none- list
levels 3 -none- character
call 5 -none- call
> p4<- predict(m4, irisr[101:150,], type="class")
#Gives me this error ! How can I solve this ?
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "naiveBayes"
Sie sollten angeben, welche Pakete Sie verwenden. Ich nehme e1071 an? – Dason
Ja ich benutze e1071 Paket! –