MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / fit

Method fit

hmm_class/hmm_classifier.py:25–38  ·  view source on GitHub ↗
(self, X, Y, V)

Source from the content-addressed store, hash-verified

23 pass
24
25 def fit(self, X, Y, V):
26 K = len(set(Y)) # number of classes - assume 0..K-1
27 N = len(Y)
28 self.models = []
29 self.priors = []
30 for k in range(K):
31 # gather all the training data for this class
32 thisX = [x for x, y in zip(X, Y) if y == k]
33 C = len(thisX)
34 self.priors.append(np.log(C) - np.log(N))
35
36 hmm = HMM(5)
37 hmm.fit(thisX, V=V, print_period=1, learning_rate=1e-2, max_iter=80)
38 self.models.append(hmm)
39
40 def score(self, X, Y):
41 N = len(Y)

Callers 1

mainFunction · 0.95

Calls 2

fitMethod · 0.95
HMMClass · 0.90

Tested by

no test coverage detected