predict.NaiveBayes.Rd
Similar 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
)
S3
methods
R6Class object
A "NaiveBayes" object for prediction.
DataFrame
DataFrame containting the data.
character
Name of the ID column.
character of list of characters, optional
Name of feature columns for prediction.
If not provided, it defaults to all non-key columns of data.
double, optional
Laplace smoothing value. Set a positive
value to enable Laplace smoothing
for categorical variables and use that
value as the smoothing parameter.
Set value 0 to disable Laplace smoothing.
Defaults to the alpha value in the JSON model,
if there is one, or 0 otherwise.
logical, optional
If TRUE, output all classes and the corresponding
confidences for each data point.
Defaults to FALSE.
double, optional
Controls the proportion of available threads that can be used by this
function.
The value range is from 0 to 1, where 0 indicates a single thread,
and 1 indicates all available threads.
Values between 0 and 1 will use up to
that percentage of available threads.Values outside this
range are ignored.
Defaults to 0.
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