NlpTools API
Class

NlpTools\Classifiers\MultinomialNBClassifier

class MultinomialNBClassifier implements ClassifierInterface

Use a multinomia NB model to classify a document

Methods

__construct(FeatureFactoryInterface $ff, MultinomialNBModelInterface $m)

string classify(array $classes, DocumentInterface $d)

Compute the probability of $d belonging to each class successively and return that class that has the maximum probability.

float getScore(string $class, DocumentInterface $d)

Compute the log of the probability of the Document $d belonging to class $class.

Details

at line 19
public __construct(FeatureFactoryInterface $ff, MultinomialNBModelInterface $m)

at line 34
public string classify(array $classes, DocumentInterface $d)

Compute the probability of $d belonging to each class successively and return that class that has the maximum probability.

Parameters

array $classes The classes from which to choose
DocumentInterface $d The document to classify

Return Value

string $class The class that has the maximum probability

at line 61
public float getScore(string $class, DocumentInterface $d)

Compute the log of the probability of the Document $d belonging to class $class.

We compute the log so that we can sum over the
logarithms instead of multiplying each probability.

Parameters

string $class The class for which we are getting a score
DocumentInterface $d The document whose score we are getting

Return Value

float The log of the probability of $d belonging to $class