-
Notifications
You must be signed in to change notification settings - Fork 293
/
demo_pair_plot_movies_phate.py
36 lines (30 loc) · 1.05 KB
/
demo_pair_plot_movies_phate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
try:
import phate
except:
print('Install phate using $ pip install -U phate matplotlib')
exit(1)
import scattertext as st
movie_df = st.SampleCorpora.RottenTomatoes.get_data()
movie_df.category = movie_df.category \
.apply(lambda x: {'rotten': 'Negative', 'fresh': 'Positive', 'plot': 'Plot'}[x])
corpus = st.CorpusFromPandas(
movie_df,
category_col='movie_name',
text_col='text',
nlp=st.whitespace_nlp_with_sentences
).build().get_stoplisted_unigram_corpus()
html = st.produce_pairplot(
corpus,
category_projector=st.CategoryProjector(projector=phate.PHATE()),
metadata=movie_df['category'] + ': ' + movie_df['movie_name'],
#scaler=st.Scalers.scale_0_to_1,
#show_halo=False,
#d3_url_struct=st.D3URLs(
# d3_scale_chromatic_url='scattertext/data/viz/scripts/d3-scale-chromatic.v1.min.js',
# d3_url='scattertext/data/viz/scripts/d3.min.js'
#),
default_to_term_comparison=False
)
file_name = 'movie_pair_plot_phates.html'
open(file_name, 'wb').write(html.encode('utf-8'))
print('./' + file_name)