Closed bassimeledath closed 5 years ago
It's hard to tell exactly what's going on without seeing the contents of data
which is presumably a pandas.DataFrame.
Your category_name
(currently 'Positive') parameter must in a value in the column 'sentiment' in data
. The error is saying that isn't. The same thing holds for Negative
.
Also, the metadata
parameter should be a array-like object that's the same length as data, and holds the titles for each of the documents shown.
The Pandas DataFrame has 3 columns - reviews, stars and sentiment, where sentiment is a binary categorical variable (positive or negative). Reviews are strings and stars can range from 1-5.
I changed my code to the one below (seeing as metadata is an optional param I dropped it):
html = produce_scattertext_explorer(corpus, category='sentiment', category_name='positive', not_category_name='negative', width_in_pixels=1000, minimum_term_frequency=5, term_significance = st.LogOddsRatioUninformativeDirichletPrior(), include_term_category_counts=False) file_name = 'test.html' open(file_name, 'wb').write(html.encode('utf-8')) IFrame(src=file_name, width = 1200, height=700)
Getting this error:
AssertionError Traceback (most recent call last)
scattertext_use.pdf Here is an attached pdf of my code and output.
Apologies! I misread your code. The category
parameter should be 'positive'
. The category_name
is what the category will be rendered on the plot.
Works perfectly! Thanks!
Little background: corpus = st.CorpusFromPandas(data, category_col='sentiment', text_col='reviews',nlp=nlp).build() works just fine.
My code:
html = produce_scattertext_explorer(corpus, category='sentiment', category_name='Positive', not_category_name='Negative', width_in_pixels=1000, minimum_term_frequency=5, metadata = 'stars', term_significance = st.LogOddsRatioUninformativeDirichletPrior(), include_term_category_counts=True)
The error:
AssertionError Traceback (most recent call last)