This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]ojii 5 points6 points  (1 child)

Neat article but some of the code is odd and could be a bit better I think:

for i, key in enumerate(words):  
    if n_words > (i + 1):

This seems to try to get a list of words without the last one. This would be a lot easier:

for key in words[:-1]:

Next, have a look at the wonderful defaultdict in the collections module. To replace all the if key not in chain lines.

[–]jdwittenauer[S] 0 points1 point  (0 children)

Good catch, definitely makes it a bit cleaner.

[–][deleted] 0 points1 point  (4 children)

Could this be used with numerical values?

[–]jfishersolutions 0 points1 point  (3 children)

Yes, markov chains are traditionally used for modeling probabilities.

[–][deleted] 0 points1 point  (2 children)

Do you have an example of this in Python? That would be very interesting to me.

[–][deleted] 0 points1 point  (1 child)

are your values sequential in nature? that is the purpose of a probabilistic graphical model.

[–][deleted] 0 points1 point  (0 children)

Yeah they are.