Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bob7783 committed May 24, 2024
1 parent abc83f5 commit 3aaa09b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions hmm_class/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# https://udemy.com/unsupervised-machine-learning-hidden-markov-models-in-python
# http://lazyprogrammer.me
# Create a Markov model for site data.
from __future__ import print_function, division
from future.utils import iteritems
import numpy as np

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

# normalize
for k, v in transitions.iteritems():
for k, v in iteritems(transitions):
s, e = k
transitions[k] = v / row_sums[s]

# initial state distribution
print "initial state distribution:"
for k, v in transitions.iteritems():
print("initial state distribution:")
for k, v in iteritems(transitions):
s, e = k
if s == '-1':
print e, v
print(e, v)

# which page has the highest bounce?
for k, v in transitions.iteritems():
for k, v in iteritems(transitions):
s, e = k
if e == 'B':
print "bounce rate for %s: %s" % (s, v)
print("bounce rate for %s: %s" % (s, v))

0 comments on commit 3aaa09b

Please sign in to comment.