How to create a word cloud from a corpus in Python?

from wordcloud import WordCloud, STOPWORDS import matplotlib.pyplot as plt stopwords = set(STOPWORDS) def show_wordcloud(data, title = None): wordcloud = WordCloud( background_color=”white”, stopwords=stopwords, max_words=200, max_font_size=40, scale=3, random_state=1 # chosen at random by flipping a coin; it was heads ).generate(str(data)) fig = plt.figure(1, figsize=(12, 12)) plt.axis(‘off’) if title: fig.suptitle(title, fontsize=20) fig.subplots_adjust(top=2.3) plt.imshow(wordcloud) plt.show() show_wordcloud(Samsung_Reviews_Negative[‘Reviews’]) show_wordcloud(Samsung_Reviews_positive[‘Reviews’])

Programmatically install NLTK corpora / models, i.e. without the GUI downloader?

The NLTK site does list a command line interface for downloading packages and collections at the bottom of this page : http://www.nltk.org/data The command line usage varies by which version of Python you are using, but on my Python2.6 install I noticed I was missing the ‘spanish_grammar’ model and this worked fine: python -m nltk.downloader … Read more

How can I change the default Mysql connection timeout when connecting through python?

Do: con.query(‘SET GLOBAL connect_timeout=28800’) con.query(‘SET GLOBAL interactive_timeout=28800’) con.query(‘SET GLOBAL wait_timeout=28800′) Parameter meaning (taken from MySQL Workbench in Navigator: Instance > Options File > Tab “Networking” > Section “Timeout Settings”) connect_timeout: Number of seconds the mysqld server waits for a connect packet before responding with ‘Bad handshake’ interactive_timeout Number of seconds the server waits for activity … Read more

Creating a new corpus with NLTK

After some years of figuring out how it works, here’s the updated tutorial of How to create an NLTK corpus with a directory of textfiles? The main idea is to make use of the nltk.corpus.reader package. In the case that you have a directory of textfiles in English, it’s best to use the PlaintextCorpusReader. If … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)