Skip to content

Commit 3aaa09b

Browse files
committedMay 24, 2024·
update
1 parent abc83f5 commit 3aaa09b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
 

‎hmm_class/sites.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# https://udemy.com/unsupervised-machine-learning-hidden-markov-models-in-python
33
# http://lazyprogrammer.me
44
# Create a Markov model for site data.
5+
from __future__ import print_function, division
6+
from future.utils import iteritems
57
import numpy as np
68

79
transitions = {}
@@ -14,19 +16,19 @@
1416
row_sums[s] = row_sums.get(s, 0.) + 1
1517

1618
# normalize
17-
for k, v in transitions.iteritems():
19+
for k, v in iteritems(transitions):
1820
s, e = k
1921
transitions[k] = v / row_sums[s]
2022

2123
# initial state distribution
22-
print "initial state distribution:"
23-
for k, v in transitions.iteritems():
24+
print("initial state distribution:")
25+
for k, v in iteritems(transitions):
2426
s, e = k
2527
if s == '-1':
26-
print e, v
28+
print(e, v)
2729

2830
# which page has the highest bounce?
29-
for k, v in transitions.iteritems():
31+
for k, v in iteritems(transitions):
3032
s, e = k
3133
if e == 'B':
32-
print "bounce rate for %s: %s" % (s, v)
34+
print("bounce rate for %s: %s" % (s, v))

0 commit comments

Comments
 (0)
Please sign in to comment.