plot_ngrams
method plot_ngrams(ngram="bigram", index=None, show=10, title=None, legend="lower right", figsize=None, filename=None, display=True)[source]
Plot n-gram frequencies.
The text for the plot is extracted from the column named
corpus
. If there is no column with that name, an exception
is raised. If the documents are not tokenized, the words are
separated by spaces.
Tip
Use atom's tokenize method to separate the words creating n-grams based on their frequency in the corpus.
Parameters | ngram: str or int, default="bigram"
Number of contiguous words to search for (size of n-gram).
Choose from: words (1), bigrams (2), trigrams (3),
quadgrams (4).
index: int, str, slice, sequence or None, default=None
Documents in the corpus to include in the search. If None,
it selects all documents in the dataset.
show: int, default=10
Number of n-grams (ordered by number of occurrences) to
show in the plot.
title: str, dict or None, default=None
Title for the plot.
legend: str, dict or None, default="lower right"
Legend for the plot. See the user guide for
an extended description of the choices.
figsize: tuple or None, default=None
Figure's size in pixels, format as (x, y). If None, it
adapts the size to the number of n-grams shown.
filename: str or None, default=None
Save the plot using this name. Use "auto" for automatic
naming. The type of the file depends on the provided name
(.html, .png, .pdf, etc...). If display: bool or None, default=Truefilename has no file type,
the plot is saved as html. If None, the plot is not saved.
Whether to render the plot. If None, it returns the figure.
|
Returns | go.Figure or None
Plot object. Only returned if display=None .
|
Example
>>> from atom import ATOMClassifier
>>> from sklearn.datasets import fetch_20newsgroups
>>> X, y = fetch_20newsgroups(
... return_X_y=True,
... categories=[
... 'alt.atheism',
... 'sci.med',
... 'comp.windows.x',
... ],
... shuffle=True,
... random_state=1,
... )
>>> X = np.array(X).reshape(-1, 1)
>>> atom = ATOMClassifier(X, y)
>>> atom.textclean()
>>> atom.textnormalize()
>>> atom.plot_ngrams()