Ejemplo n.º 1
0
// virtual
void GNaiveBayes::trainInner(const GMatrix& features, const GMatrix& labels)
{
	if(!features.relation().areNominal())
		throw Ex("GNaiveBayes only supports nominal features. Perhaps you should wrap it in a GAutoFilter.");
	if(!labels.relation().areNominal())
		throw Ex("GNaiveBayes only supports nominal labels. Perhaps you should wrap it in a GAutoFilter.");
	beginIncrementalLearningInner(features.relation(), labels.relation());
	for(size_t n = 0; n < features.rows(); n++)
		trainIncremental(features[n], labels[n]);
}
Ejemplo n.º 2
0
// virtual
void GNaiveInstance::trainInner(const GMatrix& features, const GMatrix& labels)
{
	if(!features.relation().areContinuous())
		throw Ex("GNaiveInstance only supports continuous features. Perhaps you should wrap it in a GAutoFilter.");
	if(!labels.relation().areContinuous())
		throw Ex("GNaiveInstance only supports continuous labels. Perhaps you should wrap it in a GAutoFilter.");

	beginIncrementalLearningInner(features.relation(), labels.relation());
	for(size_t i = 0; i < features.rows(); i++)
		trainIncremental(features[i], labels[i]);
}
Ejemplo n.º 3
0
GNaiveInstance::GNaiveInstance(GDomNode* pNode, GLearnerLoader& ll)
: GIncrementalLearner(pNode, ll), m_pHeap(NULL)
{
	m_pAttrs = NULL;
	m_pValueSums = NULL;
	m_nNeighbors = (size_t)pNode->field("neighbors")->asInt();
	beginIncrementalLearningInner(*m_pRelFeatures, *m_pRelLabels);
	GDomNode* pAttrs = pNode->field("attrs");
	GDomListIterator it(pAttrs);
	if(it.remaining() != m_pRelFeatures->size())
		throw Ex("Expected ", to_str(m_pRelFeatures->size()), " attrs, got ", to_str(it.remaining()), " attrs");
	m_pHeap = new GHeap(1024);
	for(size_t i = 0; i < m_pRelFeatures->size(); i++)
	{
		delete(m_pAttrs[i]);
		m_pAttrs[i] = new GNaiveInstanceAttr(it.current(), m_pRelLabels->size(), m_pHeap);
		it.advance();
	}
}