Markov chain using processing - Python

0 votes

I have a function def for Markov chain to create sentences. This is def:

def createProbabilityHash(words):
    numWords = len(words)
    wordCount = {}
    for word in words:
        if wordCount.has_key(word):
            wordCount[word] += 1
        else:
            wordCount[word] = 1

Now I want a definition to build the same thing in processing. Can someone help me out with it? Thank you!

Aug 2, 2019 in Machine Learning by Gujjar
917 views

1 answer to this question.

0 votes

Try something like this @Gujjar

HashMap<String, int> wordCount;

int createProbabilityHash(words):
    int numWords = words.size();
    wordCount = new HashMap<String, int>();
    for (int i = 0;i < numWords; ++i) {
        if wordCount.containsKey(words[i]) {
            wordCount.put(words[i], wordCount.get(words[i]) + 1);
        } else {
            wordCount.put(words[i], 1);
        }
    }
answered Aug 2, 2019 by Ashish

Related Questions In Machine Learning

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Example to run KNN algorithm using python

Have a look at this one: from sklearn.datasets ...READ MORE

answered May 9, 2019 in Machine Learning by Harvy
1,581 views
0 votes
1 answer
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,070 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP