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

Method __init__

pattern/vector/__init__.py:2052–2059  ·  view source on GitHub ↗

k-nearest neighbor (kNN) is a simple supervised learning method for text classification. Documents are classified by a majority vote of nearest neighbors (cosine distance) in the training data.

(self, k=10, distance=COSINE, train=[], baseline=FREQUENCY)

Source from the content-addressed store, hash-verified

2050class KNN(Classifier):
2051
2052 def __init__(self, k=10, distance=COSINE, train=[], baseline=FREQUENCY):
2053 """ k-nearest neighbor (kNN) is a simple supervised learning method for text classification.
2054 Documents are classified by a majority vote of nearest neighbors (cosine distance)
2055 in the training data.
2056 """
2057 self.k = k # Number of nearest neighbors to observe.
2058 self.distance = distance # COSINE, EUCLIDEAN, ...
2059 Classifier.__init__(self, train, baseline)
2060
2061 def train(self, document, type=None):
2062 """ Trains the classifier with the given document of the given type (i.e., class).

Callers

nothing calls this directly

Calls 1

__init__Method · 0.45

Tested by

no test coverage detected