Class NaiveBayesModel
source code
object --+
         |
        NaiveBayesModel
Model for Naive Bayes classifiers.
Contains two parameters:
- pi: vector of logs of class priors (dimension C)
- theta: matrix of logs of class conditional probabilities (CxD)
>>> data = [
...     LabeledPoint(0.0, [0.0, 0.0]),
...     LabeledPoint(0.0, [0.0, 1.0]),
...     LabeledPoint(1.0, [1.0, 0.0]),
... ]
>>> model = NaiveBayes.train(sc.parallelize(data))
>>> model.predict(array([0.0, 1.0]))
0.0
>>> model.predict(array([1.0, 0.0]))
1.0
>>> sparse_data = [
...     LabeledPoint(0.0, SparseVector(2, {1: 0.0})),
...     LabeledPoint(0.0, SparseVector(2, {1: 1.0})),
...     LabeledPoint(1.0, SparseVector(2, {0: 1.0}))
... ]
>>> model = NaiveBayes.train(sc.parallelize(sparse_data))
>>> model.predict(SparseVector(2, {1: 1.0}))
0.0
>>> model.predict(SparseVector(2, {0: 1.0}))
1.0
    |  | 
        
          | __init__(self,
        labels,
        pi,
        theta) x.__init__(...) initializes x; see help(type(x)) for signature
 | source code |  | 
    |  | 
        
          | predict(self,
        x) Return the most likely class for a data vector x
 | source code |  | 
  
    | Inherited from object:__delattr__,__format__,__getattribute__,__hash__,__new__,__reduce__,__reduce_ex__,__repr__,__setattr__,__sizeof__,__str__,__subclasshook__ | 
  
    | Inherited from object:__class__ | 
| 
  | __init__(self,
        labels,
        pi,
        theta)
    (Constructor)
 | source code |  x.__init__(...) initializes x; see help(type(x)) for signature 
    Overrides:
        object.__init__
        (inherited documentation) |