|
|
typedef Clonable_Impl< Classifier_Multinomial_NaiveBayes, Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > > | parent_impl |
| | implements clone(); sharing/stateless_clone throw in Classifier
|
|
typedef std::shared_ptr< DATAACCESSOR > | PDataAccessor |
| | shared pointer to the data accessor supplying train/test blocks
|
|
typedef std::shared_ptr< SUBSET > const | PSubset |
| | shared pointer to the (fixed, non-reassignable) feature subset being trained/evaluated on
|
|
typedef DATAACCESSOR::PPattern | PPattern |
| | one data sample as exposed by DATAACCESSOR (a raw pointer to its feature vector)
|
|
typedef std::shared_ptr< DATAACCESSOR > | PDataAccessor |
| | shared pointer to the data accessor supplying train/test blocks
|
|
typedef std::shared_ptr< SUBSET > const | PSubset |
| | shared pointer to the (fixed, non-reassignable) feature subset being evaluated
|
|
typedef DATAACCESSOR::PPattern | PPattern |
| | one data sample as exposed by DATAACCESSOR (a raw pointer to its feature vector)
|
|
| void | enable_prelearn_mode (const PDataAccessor da) |
|
void | disable_prelearn_mode () |
| | reverts to the default (per-train() relearning) mode; see enable_prelearn_mode()
|
|
bool | get_prelearn_mode () const |
| | true if enable_prelearn_mode() is currently in effect
|
| void | initialize (const PDataAccessor da) |
| virtual bool | classify (DIMTYPE &cls, const PPattern &pattern) override |
| virtual bool | classify_scores (std::vector< RETURNTYPE > &scores, const PPattern &pattern) override |
| virtual bool | test_confusion (std::vector< RETURNTYPE > &confusion, DIMTYPE &classes, const PDataAccessor da) override |
| virtual bool | train (const PDataAccessor da, const PSubset sub) override |
| | learns from designated training part of data
|
| virtual bool | test (RETURNTYPE &result, const PDataAccessor da) override |
|
DIMTYPE | get_n () const |
| | the underlying model's full ("raw") learned dimensionality (Model_Multinomial::get_n())
|
|
DIMTYPE | get_d () const |
| | the underlying model's current virtual (narrowed) dimensionality (Model_Multinomial::get_d())
|
| virtual std::ostream & | print (std::ostream &os) const override |
| | writes a human-readable identification of the object; base default writes nothing
|
| Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > * | clone () const override |
| | dispatches to the DEEP_KIND mechanism (default CLONE_DEEP: Derived's copy-constructor)
|
| Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > * | sharing_clone () const override |
| | dispatches to the SHARING_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
|
| Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > * | stateless_clone () const override |
| | dispatches to the STATELESS_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
|
| virtual bool | test_scores (std::vector< std::pair< RETURNTYPE, DIMTYPE > > &scores, const PDataAccessor da) |
| virtual bool | test_scores_matrix (std::vector< RETURNTYPE > &scores, std::vector< DIMTYPE > &labels, DIMTYPE &classes, const PDataAccessor da) |
| virtual bool | test_metric (RETURNTYPE &result, const PDataAccessor da, const Metric_Spec< RETURNTYPE > &spec) |
| bool | is_clone () const |
|
bool | is_sharing () const |
| | true if this instance is a sharing_clone() result (referencing, not owning, the source's structures)
|
|
bool | is_sharing_clone () const |
| | true if this instance is BOTH a clone and sharing – i.e. specifically a sharing_clone() result, not a clone()/stateless_clone() one
|
template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
class FST::Classifier_Multinomial_NaiveBayes< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >
Implements Naive-like Bayes classifier based on multinomial model.
The document classification rule of the multinomial model (Model_Multinomial): a pattern is assigned to the class maximizing
ln P(c) + sum over the selected features f of x[f] * ln theta(f|c)
where x[f] is the pattern's term count and theta(f|c) the class-conditional term probability the model learned. This is the log-posterior up to the constants (the multinomial coefficient and the evidence) that are the same for every class and therefore cannot change the argmax.
"Naive-LIKE" rather than plain Naive Bayes: the per-feature factors are the multinomial term probabilities of one shared word distribution per class, not independent per-feature distributions - the feature contributions are coupled through theta's normalization over the selected features, so the usual conditional-independence reading does not apply literally.
- Warning
- A ONE-FEATURE subset is degenerate here: with a single feature theta(f|c)==1 in every class, every log term vanishes and the score no longer depends on the data at all. The class treats such subsets as unusable rather than pretending to classify them, and does so consistently: classify() returns false, test() reports accuracy 0, the confusion matrix holds one off-diagonal count (so every confusion-based metric is 0 as well), and classify_scores() returns all-equal scores (AUC 0.5). Feature selection driven by this classifier therefore never settles on a single feature.
template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
Classifies one pattern; on success cls receives the predicted class index (0-based, in [0,classes)). Returns false when no decision can be made at all - the model has not been trained, or the implementation hit an unrecoverable condition; false is not a "reject" option and aborts the enclosing test loop.
Implements FST::Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR >.