Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 09-frequency-distributions.md #13

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update 09-frequency-distributions.md
improved readability of the solutions as well as correctness matching the tasks
previous one did not filter "one", "two", "three" as described in the tasks
annajiat authored Jul 12, 2021
commit 20d80c13f7d3fd1e0d39a5777a32446104b66c14
22 changes: 11 additions & 11 deletions _episodes/09-frequency-distributions.md
Original file line number Diff line number Diff line change
@@ -99,14 +99,14 @@ plt.axis("off")
> > ## Answer
> >
> > ~~~python
> > numbers=list(map(str, range(0,1000000)))
> > otherTokens=["..."]
> > numbers = list(map(str, range(0,1000000)))
> > otherTokens = ["...", "one", "two", "three"]
> > remove_these = set(stopwords.words('english') + list(string.punctuation) + numbers + otherTokens)
> > filtered_text = [w for w in lower_india_tokens if not w in remove_these]
> > filtered_text_new = [w for w in lower_india_tokens if not w in remove_these]
> > fdist_filtered = FreqDist(filtered_text_new)
> > fdist_filtered.plot(30,title='Frequency distribution for 30 most common tokens in our text collection (excluding stopwords, punctuation, numbers etc.)')
> > fdist_filtered.plot(30,title = 'Frequency distribution for 30 most common tokens in our text collection (excluding stopwords, punctuation, numbers etc.)')
> > ~~~
> > ![Frequency distribution for 30 most common tokens in our text collection (excluding stopwords, punctuation, numbers etc.)](../fig/fdist2.png)
> > ![Frequency distribution for 30 most common tokens in our text collection (excluding stopwords, punctuation, numbers etc.)](../fig/fdist2_updated.png)
> {: .solution}
{: .challenge}

@@ -116,18 +116,18 @@ plt.axis("off")
> Redraw the word cloud with the updated ```filtered_text``` variable (after removing the strings in Task 1).
>
> > ## Answer
> >
> > ~~~python
> > dictionary=Counter(filtered_text)
> > import matplotlib.pyplot as plt
> > from wordcloud import WordCloud
> > cloud = WordCloud(max_font_size=80,colormap="hsv").generate_from_frequencies(dictionary)
> > plt.figure(figsize=(16,12))
> > plt.imshow(cloud, interpolation='bilinear')
> >
> > dictionary = Counter(filtered_text_new)
> > cloud = WordCloud(max_font_size = 80, colormap = "hsv").generate_from_frequencies(dictionary)
> > plt.figure(figsize = (16, 12))
> > plt.imshow(cloud, interpolation = 'bilinear')
> > plt.axis('off')
> > plt.show()
> > ~~~
> > ![New word cloud](../fig/wordcloud1.png)
> > ![New word cloud](../fig/wordcloud1_updated.png)
> {: .solution}
{: .challenge}