verticapy.machine_learning.memmodel.naive_bayes.NaiveBayes.predict_proba#
- NaiveBayes.predict_proba(X: list | ndarray) ndarray #
Computes the model’s probabilites using the input matrix.
Parameters#
- X: list | numpy.array
The data on which to make the prediction.
Returns#
- numpy.array
Probabilities.
Examples#
Import the required module.
from verticapy.machine_learning.memmodel.naive_bayes import NaiveBayes
Let’s define attributes representing each input feature:
attributes = [ { "type": "gaussian", "C": {"mu": 63.9878308300395, "sigma_sq": 7281.87598377196}, "Q": {"mu": 13.0217386792453, "sigma_sq": 211.626862330204}, "S": {"mu": 27.6928120412844, "sigma_sq": 1428.57067393938}, }, { "type": "multinomial", "C": 0.771666666666667, "Q": 0.910714285714286, "S": 0.878216123499142, }, { "type": "bernoulli", "C": 0.771666666666667, "Q": 0.910714285714286, "S": 0.878216123499142, }, { "type": "categorical", "C": { "female": 0.407843137254902, "male": 0.592156862745098, }, "Q": { "female": 0.416666666666667, "male": 0.583333333333333, }, "S": { "female": 0.406666666666667, "male": 0.593333333333333, }, }, ]
We also need to provide class names and their prior probabilities.
prior = [0.8, 0.1, 0.1] classes = ["C", "Q", "S"]
Let’s create a model.
model_nb = NaiveBayes(attributes, prior, classes)
Create a dataset.
data = [ [40.0, 1, True, "male"], [60.0, 3, True, "male"], [15.0, 2, False, "female"], ]
Compute the predictions.
model_nb.predict_proba(data) Out[7]: array([[0.64564673, 0.12105224, 0.23330103], [0.74783083, 0.00570541, 0.24646376], [0.34471925, 0.49592024, 0.15936051]])
Note
Refer to
NaiveBayes
for more information about the different methods and usages.