predict.textmodel_nb.Rd
predict.textmodel_nb()
implements class predictions from a fitted
Naive Bayes model. using trained Naive Bayes examples
# S3 method for textmodel_nb predict( object, newdata = NULL, type = c("class", "probability", "logposterior"), force = FALSE, ... )
object | a fitted Naive Bayes textmodel |
---|---|
newdata | dfm on which prediction should be made |
type | the type of predicted values to be returned; see Value |
force | make newdata's feature set conformant to the model terms |
... | not used |
predict.textmodel_nb
returns either a vector of class
predictions for each row of newdata
(when type = "class"
), or
a document-by-class matrix of class probabilities (when type =
"probability"
) or log posterior likelihoods (when type =
"logposterior"
).
# application to LBG (2003) example data (tmod <- textmodel_nb(data_dfm_lbgexample, y = c("A", "A", "B", "C", "C", NA)))#> #> Call: #> textmodel_nb.dfm(x = data_dfm_lbgexample, y = c("A", "A", "B", #> "C", "C", NA)) #> #> Distribution: multinomial; prior: uniform; smoothing value: 1; 5 training documents; 37 fitted features.predict(tmod)#> R1 R2 R3 R4 R5 V1 #> A A B C C B #> Levels: A B C#> A B C #> R1 -2687.853 -6472.926 -7614.264 #> R2 -2687.853 -4013.332 -7147.946 #> R3 -4671.788 -2368.923 -4671.788 #> R4 -7147.946 -4013.332 -2687.853 #> R5 -7614.264 -6472.926 -2687.853 #> V1 -3212.036 -3007.763 -6381.702