predict.NaiveBayes.RdSimilar to other predict methods, this function predicts fitted values from a fitted "NaiveBayes" object.
# S3 method for NaiveBayes predict( model, data, key, features = NULL, alpha = NULL, verbose = NULL, thread.ratio = NULL )
| model |
|
|---|---|
| data |
|
| key |
|
| features |
|
| alpha |
|
| verbose |
|
| thread.ratio |
|
S3 methods
Predicted values are returned as a DataFrame, structured as follows.
ID - with the same name and type as
data's ID column.
CLASS - predicted class name
CONFIDENCE - confidence for
the prediction of the sample, which is a
logarithmic value of the posterior probabilities.
A non-zero Laplace value (alpha) is required if there exist discrete category values that only occur in the test set. It can be read from JSON models or from the parameter alpha in predict(). The Laplace value you set here takes precedence over the values read from JSON models.
Input DataFrame df2 for prediction:
> df2$Collect() ID HOMEOWNER MARITALSTATUS ANNUALINCOME 1 0 NO Married 120.0 2 1 YES Married 180.0 3 2 NO Single 90.0
Call the function and predict with a "NaiveBayes" object nb:
> predict(nb, df2, "ID", alpha=1.0, verbose=TRUE) ID CLASS CONFIDENCE 1 0 NO -6.572353 2 0 YES -23.747252 3 1 NO -7.602221 4 1 YES -169.133547 5 2 NO -7.133599 6 2 YES -4.648640