GClasses

GClasses::GNaiveBayes Class Reference

A naive Bayes classifier. More...

#include <GNaiveBayes.h>

Inheritance diagram for GClasses::GNaiveBayes:
GClasses::GIncrementalLearner GClasses::GSupervisedLearner GClasses::GTransducer

List of all members.

Public Member Functions

 GNaiveBayes (GRand &rand)
 GNaiveBayes (GDomNode *pNode, GLearnerLoader &ll)
 Load from a DOM.
virtual ~GNaiveBayes ()
virtual GDomNodeserialize (GDom *pDoc)
 Marshal this object into a DOM, which can then be converted to a variety of serial formats.
virtual void trainSparse (GSparseMatrix &features, GMatrix &labels)
 See the comment for GIncrementalLearner::trainSparse This method assumes that the values in pData are all binary values (0 or 1).
void setEquivalentSampleSize (double d)
 To ensure that unsampled values don't dominate the joint distribution by multiplying by a zero, each value is given at least as much representation as specified here. (The default is 0.5, which is as if there were half of a sample for each value.)
double equivalentSampleSize ()
 Returns the equivalent sample size. (The number of samples of each possible value that is added by default to prevent zeros.)
virtual void clear ()
 See the comment for GSupervisedLearner::clear.
void autoTune (GMatrix &features, GMatrix &labels)
 Uses cross-validation to find a set of parameters that works well with the provided data.

Static Public Member Functions

static void test ()
 Performs unit tests for this class. Throws an exception if there is a failure.

Protected Member Functions

virtual void trainInner (GMatrix &features, GMatrix &labels)
 See the comment for GSupervisedLearner::trainInner.
virtual void predictInner (const double *pIn, double *pOut)
 See the comment for GSupervisedLearner::predictInner.
virtual void predictDistributionInner (const double *pIn, GPrediction *pOut)
 See the comment for GSupervisedLearner::predictDistributionInner.
virtual bool canImplicitlyHandleContinuousFeatures ()
 See the comment for GTransducer::canImplicitlyHandleContinuousFeatures.
virtual bool canImplicitlyHandleContinuousLabels ()
 See the comment for GTransducer::canImplicitlyHandleContinuousLabels.
virtual void beginIncrementalLearningInner (sp_relation &pFeatureRel, sp_relation &pLabelRel)
 See the comment for GIncrementalLearner::beginIncrementalLearningInner.
virtual void trainIncrementalInner (const double *pIn, const double *pOut)
 Adds a single training sample to the collection.

Protected Attributes

sp_relation m_pFeatureRel
sp_relation m_pLabelRel
size_t m_nSampleCount
GNaiveBayesOutputAttr ** m_pOutputs
double m_equivalentSampleSize

Detailed Description

A naive Bayes classifier.


Constructor & Destructor Documentation

GClasses::GNaiveBayes::GNaiveBayes ( GRand rand)
GClasses::GNaiveBayes::GNaiveBayes ( GDomNode pNode,
GLearnerLoader ll 
)

Load from a DOM.

virtual GClasses::GNaiveBayes::~GNaiveBayes ( ) [virtual]

Member Function Documentation

void GClasses::GNaiveBayes::autoTune ( GMatrix features,
GMatrix labels 
)

Uses cross-validation to find a set of parameters that works well with the provided data.

virtual void GClasses::GNaiveBayes::beginIncrementalLearningInner ( sp_relation pFeatureRel,
sp_relation pLabelRel 
) [protected, virtual]
virtual bool GClasses::GNaiveBayes::canImplicitlyHandleContinuousFeatures ( ) [inline, protected, virtual]
virtual bool GClasses::GNaiveBayes::canImplicitlyHandleContinuousLabels ( ) [inline, protected, virtual]
virtual void GClasses::GNaiveBayes::clear ( ) [virtual]

See the comment for GSupervisedLearner::clear.

Implements GClasses::GSupervisedLearner.

double GClasses::GNaiveBayes::equivalentSampleSize ( ) [inline]

Returns the equivalent sample size. (The number of samples of each possible value that is added by default to prevent zeros.)

virtual void GClasses::GNaiveBayes::predictDistributionInner ( const double *  pIn,
GPrediction pOut 
) [protected, virtual]
virtual void GClasses::GNaiveBayes::predictInner ( const double *  pIn,
double *  pOut 
) [protected, virtual]
virtual GDomNode* GClasses::GNaiveBayes::serialize ( GDom pDoc) [virtual]

Marshal this object into a DOM, which can then be converted to a variety of serial formats.

Implements GClasses::GSupervisedLearner.

void GClasses::GNaiveBayes::setEquivalentSampleSize ( double  d) [inline]

To ensure that unsampled values don't dominate the joint distribution by multiplying by a zero, each value is given at least as much representation as specified here. (The default is 0.5, which is as if there were half of a sample for each value.)

static void GClasses::GNaiveBayes::test ( ) [static]

Performs unit tests for this class. Throws an exception if there is a failure.

Reimplemented from GClasses::GSupervisedLearner.

virtual void GClasses::GNaiveBayes::trainIncrementalInner ( const double *  pIn,
const double *  pOut 
) [protected, virtual]

Adds a single training sample to the collection.

Implements GClasses::GIncrementalLearner.

virtual void GClasses::GNaiveBayes::trainInner ( GMatrix features,
GMatrix labels 
) [protected, virtual]
virtual void GClasses::GNaiveBayes::trainSparse ( GSparseMatrix features,
GMatrix labels 
) [virtual]

See the comment for GIncrementalLearner::trainSparse This method assumes that the values in pData are all binary values (0 or 1).

Implements GClasses::GIncrementalLearner.


Member Data Documentation

GNaiveBayesOutputAttr** GClasses::GNaiveBayes::m_pOutputs [protected]