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

Method fit

hmm_class/hmmd_tf.py:23–42  ·  view source on GitHub ↗
(self, X, max_iter=10, print_period=1)

Source from the content-addressed store, hash-verified

21 self.session = session
22
23 def fit(self, X, max_iter=10, print_period=1):
24 # train the HMM model using stochastic gradient descent
25
26 N = len(X)
27 print("number of train samples:", N)
28
29 costs = []
30 for it in range(max_iter):
31 if it % print_period == 0:
32 print("it:", it)
33
34 for n in range(N):
35 # this would of course be much faster if we didn't do this on
36 # every iteration of the loop
37 c = self.get_cost_multi(X).sum()
38 costs.append(c)
39 self.session.run(self.train_op, feed_dict={self.tfx: X[n]})
40
41 plt.plot(costs)
42 plt.show()
43
44 def get_cost(self, x):
45 # returns log P(x | model)

Callers 1

fit_coinFunction · 0.95

Calls 2

get_cost_multiMethod · 0.95
runMethod · 0.45

Tested by

no test coverage detected