MCPcopy Index your code
hub / github.com/clips/pattern / train

Method train

pattern/vector/__init__.py:1990–2005  ·  view source on GitHub ↗

Trains the classifier with the given document of the given type (i.e., class). A document can be a Document, Vector, dict, list or string. If no type is given, Document.type will be used instead.

(self, document, type=None)

Source from the content-addressed store, hash-verified

1988 return self._features.keys()
1989
1990 def train(self, document, type=None):
1991 """ Trains the classifier with the given document of the given type (i.e., class).
1992 A document can be a Document, Vector, dict, list or string.
1993 If no type is given, Document.type will be used instead.
1994 """
1995 # Calculate the probability of a class.
1996 # Calculate the probability of a feature.
1997 # Calculate the probability of a feature occuring in a class (= conditional probability).
1998 type, vector = self._vector(document, type=type)
1999 self._classes[type] = self._classes.get(type, 0) + 1
2000 self._likelihood.setdefault(type, {})
2001 for f, w in vector.iteritems():
2002 if self.method == BERNOUILLI:
2003 w = 1
2004 self._features[f] = self._features.get(f, 0) + 1
2005 self._likelihood[type][f] = self._likelihood[type].get(f, 0) + w
2006
2007 def classify(self, document, discrete=True):
2008 """ Returns the type with the highest probability for the given document.

Callers

nothing calls this directly

Calls 4

_vectorMethod · 0.80
iteritemsMethod · 0.80
getMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected