implements class predictions using trained Naive Bayes examples

# S3 method for textmodel_nb_fitted
predict(object, newdata = NULL, ...)

Arguments

object

a fitted Naive Bayes textmodel

newdata

dfm on which prediction should be made

...

not used

Value

A list of two data frames, named docs and words corresponding to word- and document-level predicted quantities

docs

data frame with document-level predictive quantities: nb.predicted, ws.predicted, bs.predicted, PcGw, wordscore.doc, bayesscore.doc, posterior.diff, posterior.logdiff. Note that the diff quantities are currently implemented only for two-class solutions.

words

data-frame with word-level predictive quantities: wordscore.word, bayesscore.word

Examples

(nbfit <- textmodel_nb(data_dfm_lbgexample, c("A", "A", "B", "C", "C", NA)))
#> Fitted Naive Bayes model: #> Call: #> textmodel_nb.dfm(x = data_dfm_lbgexample, y = c("A", "A", "B", #> "C", "C", NA)) #> #> #> Training classes and priors: #> A B C #> 0.3333333 0.3333333 0.3333333 #> #> Likelihoods: Class Posteriors: #> A B C A B C #> A 0.001472754 0.0009643202 0.000490918 0.502991108 0.32934519 0.167663703 #> B 0.001963672 0.0009643202 0.000490918 0.574356134 0.28205483 0.143589034 #> C 0.005400098 0.0009643202 0.000490918 0.787721842 0.14066708 0.071611077 #> D 0.011291114 0.0009643202 0.000490918 0.885831012 0.07565460 0.038514392 #> E 0.022582229 0.0009643202 0.000490918 0.939459587 0.04011738 0.020423035 #> F 0.039764359 0.0009643202 0.000490918 0.964695478 0.02339470 0.011909821 #> G 0.058419244 0.0009643202 0.000490918 0.975695186 0.01610570 0.008199119 #> H 0.077074129 0.0009643202 0.000490918 0.981468867 0.01227974 0.006251394 #> I 0.088856161 0.0009643202 0.000490918 0.983886440 0.01067772 0.005435837 #> J 0.094256259 0.0009643202 0.000490918 0.984795576 0.01007528 0.005129144 #> K 0.095238095 0.0028929605 0.000490918 0.965688392 0.02933383 0.004977775 #> L 0.095238095 0.0038572806 0.000490918 0.956337379 0.03873305 0.004929574 #> M 0.094256259 0.0106075217 0.000490918 0.894656434 0.10068390 0.004659669 #> N 0.088856161 0.0221793635 0.000490918 0.796727296 0.19887090 0.004401808 #> O 0.077074129 0.0443587271 0.000490918 0.632150123 0.36382344 0.004026434 #> P 0.058419244 0.0761812922 0.001472754 0.429321904 0.55985486 0.010823241 #> Q 0.039764359 0.1118611379 0.001963672 0.258900804 0.72831397 0.012785225 #> R 0.022582229 0.1417550627 0.005400098 0.133042159 0.83514341 0.031814429 #> S 0.011291114 0.1533269045 0.011291114 0.064187198 0.87162560 0.064187198 #> T 0.005400098 0.1417550627 0.022582229 0.031814429 0.83514341 0.133042159 #> U 0.001963672 0.1118611379 0.039764359 0.012785225 0.72831397 0.258900804 #> V 0.001472754 0.0761812922 0.058419244 0.010823241 0.55985486 0.429321904 #> W 0.000490918 0.0443587271 0.077074129 0.004026434 0.36382344 0.632150123 #> X 0.000490918 0.0221793635 0.088856161 0.004401808 0.19887090 0.796727296 #> Y 0.000490918 0.0106075217 0.094256259 0.004659669 0.10068390 0.894656434 #> Z 0.000490918 0.0038572806 0.095238095 0.004929574 0.03873305 0.956337379 #> ZA 0.000490918 0.0028929605 0.095238095 0.004977775 0.02933383 0.965688392 #> ZB 0.000490918 0.0009643202 0.094256259 0.005129144 0.01007528 0.984795576 #> ZC 0.000490918 0.0009643202 0.088856161 0.005435837 0.01067772 0.983886440 #> ZD 0.000490918 0.0009643202 0.077074129 0.006251394 0.01227974 0.981468867 #>
(nbpred <- predict(nbfit))
#> Predicted textmodel of type: Naive Bayes #> #> lp(A) lp(B) lp(C) Pr(A) Pr(B) Pr(C) Predicted #> R1 -2687.8527 -6472.9263 -7614.2636 1.0000 0.0000 0.0000 A #> R2 -2687.8527 -4013.3319 -7147.9465 1.0000 0.0000 0.0000 A #> R3 -4671.7885 -2368.9234 -4671.7885 0.0000 1.0000 0.0000 B #> R4 -7147.9465 -4013.3319 -2687.8527 0.0000 0.0000 1.0000 C #> R5 -7614.2636 -6472.9263 -2687.8527 0.0000 0.0000 1.0000 C #> V1 -3212.0356 -3007.7627 -6381.7021 0.0000 1.0000 0.0000 B #>