File size: 1,230 Bytes
d6f7f2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a662f5
8fb4992
aaec88e
1a662f5
d6f7f2a
 
8fb4992
d6f7f2a
8fb4992
 
 
 
 
 
 
d6f7f2a
 
 
 
 
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
import numpy as np
import pandas as pd
from gensim.corpora import Dictionary, MmCorpus
from gensim.models import LdaModel, Word2Vec
import matplotlib.pyplot as plt
import streamlit as st
from pyLDAvis import prepared_data_to_html
import pyLDAvis.gensim_models as gensimvis

# 生データ・コーパス・辞書・モデルのロード
df = pd.read_csv("./raw_corpus.csv")
corpus = MmCorpus('./corpus.mm')
dict = Dictionary.load(f'./livedoor_demo.dict')
lda = LdaModel.load('./lda_demo.model')

st.caption("生データ一覧: カテゴリごとに10個を表示")
# ここに処理を書いてください。
for k,v in (df.groupby("CATEGORY").groups).items():
    st.dataframe(df.iloc[v[:10]], height=200)

st.caption("記事のカテゴリ")
# ここに処理を書いてください。
count = df[["CATEGORY", "DOCUMENT"]].groupby("CATEGORY").count()
col1, col2 = st.columns(2)
with col1:
    st.dataframe(count)
with col2:
    fig, ax = plt.subplots()
    count.plot.pie(y="DOCUMENT", ax=ax, ylabel="", legend=False)
    st.pyplot(fig)

# pyLDAvisによるトピックの可視化
vis = gensimvis.prepare(lda, corpus, dict)
html_string = prepared_data_to_html(vis)
st.components.v1.html(html_string, width=1300, height=800)