Skip to content

Instantly share code, notes, and snippets.

@uhfx
Last active January 19, 2021 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhfx/434883a9c175eadd37dafa67aa96e1d3 to your computer and use it in GitHub Desktop.
Save uhfx/434883a9c175eadd37dafa67aa96e1d3 to your computer and use it in GitHub Desktop.
20210115
"*",
"4468",
"電話",
"(31)ウィルス対策ソフト包括ライセンス(TrendMicro)","WindowsのUpdateをしてしまったが問題あるか",
"2020/11/25",
"2020/11/25",
"",
"11/17お知らせを見る前に、WindowsのUpdateをしてしまったが問題あるか",
"10",
"2020/11/25 13:05",
"10",
"問い合わせ・相談",
"2020/11/25 13:05",
"職員",
"",
"使用しているPCは事務用一括端末(デスクトプ)とのこと
特にウィルス対策ソフトを入れなおした記憶はないとのことなので、ApexOneご利用ではないのでアナウンス対象外であることをお伝えしました",
"NW4",
"2020/11/25 12:58",
"",
""
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar1.py
text_paths = glob.glob('data/text/**/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
text = text.split('\n')
title = text[2]
text = ' '.join(text[3:])
texts.append(text)
news_ss = pd.Series(texts)
display(news_ss.head())
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
#lunar1.py
text_paths = glob.glob('data/text/**/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
text = text.split('\n')
title = text[2]
text = ' '.join(text[3:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
display(processed_news_ss.head())
# フォントの入手元 https://moji.or.jp/ipafont/ipafontdownload/
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
# lunar3.py header
from wordcloud import WordCloud
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
#lunar1.py
text_paths = glob.glob('data/text/**/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
text = text.split('\n')
title = text[2]
text = ' '.join(text[3:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
# display(processed_news_ss.head())
# lunar3.py
font_path="/Library/Fonts/ipaexg.ttf"
font_property = matplotlib.font_manager.FontProperties(fname=font_path, size=24)
# font_property = matplotlib.font_manager.FontProperties(size=24)
def show_wordcloud(series):
long_string = ','.join(list(series.values))
# Create a WordCloud object
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# wordcloud = WordCloud( background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# Generate a word cloud
wordcloud.generate(long_string)
# Visualize the word cloud
plt.imshow(wordcloud)
plt.show()
show_wordcloud(processed_news_ss)
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
# lunar3.py header
from wordcloud import WordCloud
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
#lunar4.py header
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
# lunar1.py
text_paths = glob.glob('data/text/**/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
text = text.split('\n')
title = text[2]
text = ' '.join(text[3:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
# display(processed_news_ss.head())
# lunar3.py
font_path="/Library/Fonts/ipaexg.ttf"
font_property = matplotlib.font_manager.FontProperties(fname=font_path, size=24)
# font_property = matplotlib.font_manager.FontProperties(size=24)
def show_wordcloud(series):
long_string = ','.join(list(series.values))
# Create a WordCloud object
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# wordcloud = WordCloud( background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# Generate a word cloud
wordcloud.generate(long_string)
# Visualize the word cloud
plt.imshow(wordcloud)
plt.show()
# show_wordcloud(processed_news_ss)
# lunar4.py
count_vectorizer = CountVectorizer()
count_data = count_vectorizer.fit_transform(processed_news_ss)
tfidf_vectorizer = TfidfTransformer()
tfidf_data = tfidf_vectorizer.fit_transform(count_data)
print(tfidf_data.toarray())
print(tfidf_data.shape)
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
# lunar3.py header
from wordcloud import WordCloud
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
#lunar4.py header
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
# lunar5.py header
from sklearn.model_selection import GridSearchCV
from sklearn.decomposition import LatentDirichletAllocation as LDA
#lunar1.py
text_paths = glob.glob('data/text/**/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
text = text.split('\n')
title = text[2]
text = ' '.join(text[3:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
# display(processed_news_ss.head())
# lunar3.py
font_path="/Library/Fonts/ipaexg.ttf"
font_property = matplotlib.font_manager.FontProperties(fname=font_path, size=24)
# font_property = matplotlib.font_manager.FontProperties(size=24)
def show_wordcloud(series):
long_string = ','.join(list(series.values))
# Create a WordCloud object
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# wordcloud = WordCloud( background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# Generate a word cloud
wordcloud.generate(long_string)
# Visualize the word cloud
plt.imshow(wordcloud)
plt.show()
# show_wordcloud(processed_news_ss)
# lunar4.py
count_vectorizer = CountVectorizer()
count_data = count_vectorizer.fit_transform(processed_news_ss)
tfidf_vectorizer = TfidfTransformer()
tfidf_data = tfidf_vectorizer.fit_transform(count_data)
print(tfidf_data.toarray())
print(tfidf_data.shape)
# lunar5.py
from sklearn.model_selection import GridSearchCV
from sklearn.decomposition import LatentDirichletAllocation as LDA
def gridsearch_best_model(tfidf_data, plot_enabled=True):
# Define Search Param
n_topics = [4,5,6,7,8,9]
search_params = {'n_components': n_topics}
# Init the Model
lda = LDA(max_iter=25, # Max learning iterations
learning_method='batch',
random_state=0, # Random state
n_jobs = -1, # Use all available CPUs)
)
# Init Grid Search Class
model = GridSearchCV(lda, param_grid=search_params)
# Do the Grid Search
model.fit(tfidf_data)
# Best Model
best_lda_model = model.best_estimator_
# Model Parameters
print("Best Model's Params: ", model.best_params_)
# Log Likelihood Score
print("Best Log Likelihood Score: ", model.best_score_)
# Perplexity
print("Model Perplexity: ", best_lda_model.perplexity(tfidf_data))
# Get Log Likelyhoods from Grid Search Output
log_likelyhoods_score = [round(score) for score in model.cv_results_["mean_test_score"]]
if plot_enabled:
# Show graph
plt.figure(figsize=(12, 8))
plt.plot(n_topics, log_likelyhoods_score)
plt.title("Choosing Optimal LDA Model")
plt.xlabel("Numer of Topics")
plt.ylabel("Log Likelyhood Scores")
plt.show()
return best_lda_model
(bachelor) user@MacBook-Pro bachelor % python3 lunar123456.py
File already exists.
Best Model's Params: {'n_components': 4}
Best Log Likelihood Score: -138824.45102727457
Model Perplexity: 20994.88944972521
Topic # 0 :
八重歯,犬山,紀伊國屋書店,バイキング,亜麻,草津,レナウン,木嶋,おまじない,献灯,希子,水原,イワナ,前原,浅香,新駅,一宮,千歳,烏山,紙子,阿波,提灯,うずまく,鳴門,種子,高松,ミッチ,章一,ヤス,一平,陣羽織,杏子,庄造,近松,茂兵衛,おさん,金沢,ぬき,影武者,帝国ホテル,安城,富士川,宇多津,今治,西大寺,黒部,水溶,法体の滝,山の幸,坂出,請負う,鳴門海峡,ぞんぶん,吉野川,南烏山,前川,ミッチー,キチ,東武,越谷,商店,犬丸,乗り入れる,泉岳寺,ゆめタウン,光代,芦屋,不出来,推論,じき,亮吉,尾道,持ち掛ける,不義,順二,困苦,商家,裏長屋,門左衛門,透徹,ゴーリキー,悲恋,下宿,艶笑,とらや,附近,大経師,亭主,あや子,奥方,密通,赤貧,寅次郎,溝口,手代,貸本,驟雨,八重,落とし物,ゴボウ,四日市,北口,三郷,鈴鹿,三吉,中山寺,城東,久居,豊橋,河辺,二の宮,江南,網走,八幡,ここち,石野,懐古,東奔西走,久喜,アピタ,天童,銀天,嬉野,道頓堀,河原町,郡上,伊予,武生,段原,北光,商業高校前,北大通,近畿日本鉄道,水堂,梅島,伊勢崎線,扇田,伊万里,野々井,氷見,北長池,さば,津幡,塩冶有原,五橋,砥部,上中居,三ケ,苦竹,小山東,花堂,花台,三好,発寒,色内,幸田,小菅,能美,能代,常滑,菰野,神の倉,神郡,ドトールコーヒー,福井東,台原,紙屋,岡南,糠塚,みたけ,古市,箱崎宮前,川筋,等々力,上之町,田家,宇佐,御経塚,二川,安中,和戸,志度,渋川,湯本,せんげ,滑川,宝来,室蘭,観音寺,久留,潮江,丸岡,上里,西梅田,南大阪線,中之,南町,牟佐,袋町,袋井,藤野,不動寺,南貴崎,藍住,名駅南,下之,四番丁,津原,笠松,木屋,新居浜,堀切,日宇,大博,魚津,高平,朝霧,大坪,土橋,東武動物公園,東予,大府,月輪,木津川,別宮,元町,麻布十番,高屋,東川口,東向島,飯山,札幌南,国府,駅東,東金沢,八乙女,月形,旭ヶ丘,士別,高浜,新清水,四国,植木,晴氏,武尾,青葉,わかめ,桑名,下衆,バイパス,熱海,香椎,奇人,駅前,新大阪,八王子,真菜,黒松,海産物,ビタミンe,草丈,長町,小田原,如意,ちゃめ,山東,たんぽ,東成瀬,焚き火,釣竿,轟音,野趣,高雄,鳥海,かきわける,須賀,本荘,平定,由宇,かぶりつく,田町,大原,長浜,西新橋,館林,名勝,姫路,跡地,的場,急先鋒,春日井,平塚,亀山,佐世保,ロッテリア,御徒,花巻,銚子,関口,門間,傍聴,西日暮里,蒲田,不美人,輪島,紀伊國屋,羽目板,がり,鹿島,草加,一巡,入れ歯,付けまつげ,蟹江,水臭い,セルフサービス,小樽,辛酸,菊川,一秀,政調,政経,植草,丸亀,法務省,盛岡,愛宕,苫小牧,横須賀,明石,市営,いけ好かない,うるむ,小松,天王寺,立川,一朗,讃岐,富山,真子,七尾,範疇,長屋,磐田,尼崎,おひたし,山頂,塩焼き,足利,仲違い,連れ帰る,東西線,那覇,木更津,浩平,ポン酢,諏訪,空港通,さじ,愛子,大田,函館,吉岡,若妻,パルコ,しぶき,浜松,高崎,小児,二子,天然記念物,築地,仲居,難い,ラテン語,ショウガ,家業,黒澤,滝沢,鳥取,京橋,春園,湯立,前橋,日夜,釣り上げる,ホームタウン,うどん,宮内,赤羽,弘樹,高山,山盛り,吉祥寺,南北,上梓,谷崎,潤一郎,佳苗,倦怠期,小春,ローソン,犬猿,再燃,科技,なめ,洋食,加勢,甲信越,歯肉,南国,稀少,語録,現存,伊勢,川田,大前,にぎわう,遺志,公募,ポーク,南北線,懇意,北陸,花園,年の瀬,マドンナ,靖国神社,土佐,アヒル,戸田,記帳,将棋,天神,青龍,目の敵,岡山,打ち込める,粉末,語源,落差,五反田,由利,慶子,リニア,本通,new,守山,寝屋川,流儀,東海,クジ,奇異,縁談,着工,東口,駅名,宝塚,歩み,落ち目,鳥羽,南口,丁目,消しゴム,立食,丁度,徳島,必携,歯医者,軽蔑,バックス,いかん,jr,釧路,津田沼,戯曲,文通,鮎川,略す,とまどう,よしのり,つり,のべる,ノジマ,出雲,脂肪酸,宇都宮,歯並び,ひばりヶ丘,茨木,上越,茅ヶ崎,市役所前,五日市,坂戸,朝霞,作りあげる,竹下,つくば,山道
Topic # 1 :
ディレクトリ,転載,引用,大城,相田,シチリア,反町,捕鯨,幸広,滝口,紫陽花,省吾,ひったくり,七福神,八神,東淀川,寝息,少林寺拳法,栗田,国屋,都電,根津,クジラ,谷中,ひったくる,博巳,孝雄,勇二,太一郎,千鳥足,荒川線,真山,釈放,あつみ温泉,谷根,竜治,求刑,下村,管轄,舞い戻る,目白,柴又,巡査,再演,座禅,起訴,寛永寺,叡山,高僧,金太郎,下町,呉服,鬼子母神,面影橋,雑司ヶ谷,日暮里,芭蕉,弘法大師,墨客,湯治,詩歌,参道,千駄木,恩賜,平家,万引き,義経,塩冶,佳織,野蛮,演目,召使い,敵討ち,御会式,三ノ輪,あじさい,音楽専科社,京成,毘沙門天,帝釈天,良観,大黒天,そぞろ歩き,花魁,藤永,しなる,一葉,高3,裏手,白虎隊,尊像,側壁,純然,寺町,武蔵野台,曼珠沙華,清輝,アルカリ性,スパゲッティ,海抜,左折,線路,学習院大学,鳥羽,沿岸,衛門,差し入れる,拘置,高師直,花街,神通力,女郎,頼朝,いびる,源義経,朝廷,鳴神,逃げ延びる,ばあさん,身請け,由良之助,菊之助,白浪,刃傷,残党,家臣,大星,判官,釣瓶,パナマ,生い茂る,ポラロイド,ミンククジラ,領海,弁財天,ラック,手編み,毒薬,ツタ,いさむ,通いつめる,日本体育大学,追いやる,立ち去る,川中,始発駅,室町,与謝野,明大,無念,タカラ,脇道,布袋尊,福の神,寿老人,霊気,医王寺,宝生,正井,静寂,御朱印,経時,重々しい,従兄,いふ,名刀,大名,初夜,倣う,東海道,所帯,建立,制止,論告,極刑,上野公園,めんずる,文教堂,下車,隣家,神域,人中,巡り,振り切る,奥寺,突き,紙袋,トピック,ぺったんこ,花袋,公孫樹,腹ごしらえ,いちょう,武芳,露天,世田谷線,江戸城,沁みる,こっぴどい,手本,しし,皆殺し,葛飾,清める,自由,ひとたび,風情,寝言,番頭,栄える,龍神,鬼畜,亡霊,つづける,神出鬼没,町民,文人,貸し切り,畳む,波瀾万丈,お寺,安土,桃山,無期,直角,陳述,柴島,商人,盗賊,すみやか,イズム,浜田,大声,小僧,一帯,地形,ディーラー,恐妻,寺社,しぼむ,北千住,封じ込める,至近,激励,千本,散策,捕れる,償う,武家,山手,こぎつける,けす,稲荷,校内,個体,晶子,境内,天然記念物,弁天,セピア,絶世,善人,過ち,敷地,バレンタインデー,喧騒,清らか,美少年,池内,路面,歌舞伎,家屋,ウォーホル,おえる,船越,うけあう,酸性,祀る,篠原,務め,本殿,松尾,三国志,位牌,上野,吉原,見殺し,餓死,早稲田,男子校,沙汰,切腹,ファイル,殺人,土壌,文彦,四谷,技術評論社,安産,通り抜ける,原型,鎌倉,味気,わる,武道,植える,ほとり,寺院,郷愁,田山,神宮,面影,お化け,沈没,黒田,雑居,逸話,辟易,悪人,疎む,だます,書き方,寝かしつける,赴任,旅館,庶民,廻る,推察,由緒,色紙,気軽い,公判,外回り,こる,ノベル,蟹江,ミュージカル,忠臣蔵,ホビー,路地,暴漢,異論,飢餓,踏み入れる,シャイ,屋台,内容,のろける,青山,呼び起こす,駄菓子,行き届く,隼人,ポチ,満開,区域,怪談,樹齢,贈り物,うたう,近代,高等,江戸,街路,讃歌,下る,替る,敗北,直射,老いる,モータースポーツ,提供,樋口,作り話,普遍,企む,藤木,先々,情緒,閑静,団子,接触,替わり,博物館,愛人,娯楽,中尾,有す,田舎町,メロディ,思いがけない,ひと息,立ち並ぶ,スーパーマン,抜ける,学年,参拝,窮地,男の子,一戦,纏う,中古,木々,すう,破り,リフォーム,階級,乙女,自伝,災い,甘味,不穏,重厚,不二子,チャンネル,活気,論争,演劇,交差,祈願,浅草,スリップ,バレンタイン,無断,一期一会,さまよう,東急,台風,宿る,弱まる,可能,佇む,単身,傍ら,開運,並木,天下,ルート,おじ,香緒里,通学,賑わう,洋画,警察,思い出,吹き飛ばす,佐藤,まわす,レギュラー,隆史,犯す,老若男女,シチュエーション,咲く,焼き鳥,気象,何事,インスタント,快眠,吉本興業,屋敷,指す,見下ろす,山形,買い取る,許諾,池田,色濃い,ドラッグ,明治,性行為,裕福,整備,焼きそば,来春,女装,掛ける,先ほど,容疑,一昨年,湿度,水面,共和,童貞,祝う,本業,立たす,真っ最中,転用,改変,妥当,もらう,体育館,白黒,懲役,身勝手,復刻,繰り出す,後押し,朝日新聞
Topic # 2 :
ふる,ぬいぐるみ,永野,つかさ,コマ,おはこ,載る,バンク,スカイライン,征服,アーク,うちわ,清志郎,ねる,おしらせ,釣れる,少林寺,なめこ,おし,ぞくす,暑中,振袖,僧侶,こびる,渓流,日和,カダフィ,薬丸,ボーヴォワール,秘策,国生,忌野,結納,てんかん,亀田製菓,庭木,見舞い,江原,まんま,かくれる,上祐,嚢胞,耳かき,熊田,大浜,白浜,村主,出家,オリジナルグッズ,月頃,サンコー,曜子,心神,下田,冊子,卵巣,肋骨,弓ヶ浜,撃墜,日吉キャンパス,同志社大学,大阪城ホール,裕英,リビア,本店,踏みつける,ナニワ,入田,吉佐美,たのしむ,慈悲,断絶,穢れる,太極,史浩,さいき,にじり寄る,せんせい,祇園,ちかい,磯浜,大佐,きゅう,どじ,にゅーす,秀美,機先,いする,まける,南伊豆,しかける,巨木,ブナ,ともだち,生活協同組合,日商,急所,大阪大,水曜,国交,腫瘍,じゅん,千香,おもう,生ずる,流せる,サリ,断交,一水会,仲人,背伸び,オルグ,礼装,入信,安らか,血みどろ,柿沢,仏教徒,改宗,新刊,哨戒,三菱重工業,大雄,祝す,あまた,長生,判例,雅弘,完売,目録,出来上がる,事故死,両家,こん,悪逆,悟道,南無阿弥陀仏,洋史,巣くう,いやしい,ビラ,大阪大学,オウム真理教,顔合わせ,軟派,少林寺拳法,へちま,生垣,たすける,水難,出で立ち,レントゲン,大生,指宿,饗宴,大団円,九郎,ウグイス,仲井戸麗市,ボディガード,女帝,早稲田大,釣り針,よそよそしい,ひよこ,さえずり,雑多,河畔,せせらぎ,十和田,奥入瀬川,ガーリック,廻り,ほど近い,重罰,食い違う,凶器,赤信号,せいこう,墓石,邦人,トリポリ,評議,供与,家主,つけ込む,用法,召使い,産みの親,家内,さわり,検診,トゲ,雪どけ,触診,天王,建材,左官,山門,図上,修める,苛烈,嵩山,拳法,丸太,庭師,鉄工,京劇,仕る,棟梁,達磨,国共,菩提,禅宗,木工,留袖,配布,花見,つば,ムグラ,勉学,これみよがし,礼服,勝男,こんぶ,子生,口上,末広がり,縁起物,麻糸,縁組み,ながの,びわ,熨斗,しらが,祝い酒,長もち,ならわす,喜多,春休み,駒場,他校,島国,受け付け,景勝,しきたり,剪定,獅童,オシドリ,振り袖,ラウ,和尚,方丈,ユエ,腹心,只者,弟弟子,洋輔,工費,子弟,若僧,コーリー,撃ち殺す,生い茂る,セーフティ,身幅,ミッキーマウス,藤崎,大倉,花やしき,いつみ,立川談志,マトモ,寛平,白無垢,魚類,たこやき,へび,いわし,ざりがに,たいよう,おとす,まんぼう,おとうさん,むし,かじき,秘法,右派,バリカン,湯のみ,石工,不老,座布団,みつかる,オウム,伝搬,さめる,釣り場,てんとう,国民党,腹痛,ひろう,ごちそうさま,だま,河南,死傷,湖畔,抜き,えん,ユネスコ,まち,ちる,グッズ,激昂,顕子,アヘン,たか子,木漏れ日,ふろ,号館,厳か,さかな,密売,中腰,出立,婚礼,平安,いす,いるか,和装,とうき,空爆,進行,大仏,会館,電柱,啓之,北関東,アワビ,簿記,学術,憲法,直談判,サイン,不仲,介添え,祝祭日,すっごい,荘厳,海岸,振りまく,弱虫,鍛錬,偽り,おいら,合わさる,血まみれ,特大,地色,祭り,せん,バン,取り持つ,封建,授ける,月曜日,秘蔵,篠山,黒地,ふたつ,壁紙,邂逅,納品,病名,作り物,コードレス,モスグリーン,配備,ポスト,土足,釣り竿,流暢,混同,腐れ縁,同志社大,来週,突き出す,みる,拝む,愚弄,硬派,独り占め,ギクシャク,ガーデン,風習,略式,ぶん,返還,渾然一体,花婿,文字数,連休,百合子,くも,たか,すえ,思い知る,でかける,清らか,取り扱う,昼過ぎ,宝島,fifa,双子,来客,内戦,ずるい,足首,枯れる,共闘,作者,掲示,お盆,町内,ロックンロール,床や,鰹節,標榜,ブランコ,ホームセンター,床の間,かに,見もの,耽美,一足,来月,訊ねる,噴水,スタントマン,秋葉原,正広,らん,予告編,貿易,静岡,持病,大江戸,爆撃,健一郎,なぎ倒す,友好,ごい,仏教,顕在,メディア,芝生,ミッキー,こむ,要する,信者,尊い,シャン,毎週,民度,特集,いじる,ミニ,堅苦しい,海辺,付け替える,下調べ,テラス,くびれる,四方,企画,扇子,病みつき,茂木,繁栄,秋葉,慎太郎,樹齢,武術,異彩,和室,親交,色直し,タオル,そびえる,仁義,正念場,フー,子宝,みどころ,引き続く,お好み焼き,進出,昆布,スペル,くらう
Topic # 3 :
する,なる,ある,できる,映画,思う,日本,話題,女性,ない,記事,発売,見る,いう,スマート,機能,対応,フォン,関連,発表,言う,情報,いる,多い,ネット,写真,公開,使う,モデル,結婚,利用,搭載,ドコモ,画面,世界,韓国,行う,女子,監督,サービス,男性,更新,紹介,仕事,作品,サイト,いい,可能,番組,人気,登場,撮影,ユーザー,チェック,持つ,表示,製品,放送,カメラ,選手,テレビ,やる,ゲーム,知る,向け,動画,開始,代表,東京,価格,好き,映像,ソフトウェア,相手,予定,高い,考える,シリーズ,設定,ニュース,端末,ファン,ビデオ,語る,出る,コメント,応募,販売,必要,感じる,電話,提供,開発,掲示板,恋愛,聞く,キャンペーン,メール,最大,イベント,行く,試合,機種,現在,購入,通信,注目,公式,問題,開催,会社,使用,わかる,しれる,本体,良い,リンク,商品,転職,結果,今年,サイズ,新しい,内容,プレゼント,モバイル,ドラマ,選ぶ,作る,時代,バッテリー,充電,パソコン,タブレット,出演,入る,最新,無料,サッカー,簡単,読む,気持ち,編集,操作,受ける,演じる,強い,生活,デザイン,楽しむ,容量,採用,デジタル,特集,携帯,ページ,ディスプレイ,アップ,接続,友達,ダウンロード,カード,自身,視聴,データ,当選,売れ筋,クリスマス,野球,すごい,チーム,インチ,理由,ソフトバンク,話す,電子,連続,発言,子供,便利,入れる,使える,シーン,アメリカ,全国,食べる,料理,変わる,言葉,執筆,限定,決定,画像,状態,分かる,違う,ファイル,大きい,始める,配信,増える,一番,海外,意見,部分,セット,最近,家族,魅力,美しい,楽しい,確認,五輪,参加,ケース,プロ,描く,ポイント,社長,批判,人間,液晶,見える,記録,タイプ,今後,伝える,登録,音楽,アップデート,入力,期待,一緒,実施,観る,寄せる,アイテム,経験,呼ぶ,続く,調査,企業,イメージ,種類,期間,報道,変更,おすすめ,楽しめる,見せる,よる,ソニー,最後,出す,書く,スポーツ,ゴルフ,ブランド,画素,場所,効果,活躍,悪い,機器,ゼロ,メーカー,人生,悩み,活動,書籍,環境,コンテンツ,カラー,展開,意味,女優,ショップ,ランキング,国内,インターネット,つく,ファッション,大切,家電,技術,かける,防水,主演,早い,時期,メディア,買う,サポート,起動,飲む,様子,メンバー,実現,質問,昨年,皆さん,社会,予約,終了,存在,世代,つける,かわいい,アップル,専用,難しい,大人,会場,注意,言える,出来る,撮る,合わせる,ボタン,一部,変える,幸せ,嬉しい,印象,状況,パナソニック,スタート,コア,解説,株式会社,よい,バージョン,特別,高速,決める,通り,友人,クリック,店舗,テーマ,タップ,キー,明かす,今日,企画,答える,市場,日本人,男子,お知らせ,追加,体験,取る,来る,キャラクター,投稿,中国,過去,対象,音声,契約,トップ,検索,以外,記念,フジテレビ,インタビュー,掲載,舞台,展示,選択,システム,コード,続ける,スマ,少ない,集まる,働く,求人,報じる,部屋,最初,無い,オススメ,原因,いく,オープン,説明,ジャパン,主人公,意識,メモリー,年収,かかる,獲得,若い,物語,アクション,無線,集める,用意,子ども,面白い,個人,みる,メニュー,求める,成長,影響,加える,電池,シーズン,連絡,送る,カテゴリ,ノート,詳細,向ける,再生,一般,モード,活用,上映,劇場,その他,与える,終わる,ロゴ,ケア,相談,行動,対策,生きる,基本,特徴,事件,ストーリー,挑戦,いかが,文字,大会,ロンドン,探す,芸能,レポート,中心,練習,お気に入り,優勝,最終,始まる,香川,快適,キーボード,スタイル,なでしこ,務める,ヒット,シャープ,ビジネス,出場,募集,アカウント,通話,電源,従来,頑張る,営業,ソフト,絶対,野村,ホーム,自然,お金,社員,迎える,オリジナル,含む,非常,管理,アクセス,長い,最高,上がる,予想,振り返る,最強,くる,受賞,回答,占い,リリース,ブック,押す,年間,異なる,連載,教える,国際,漫画
(bachelor) user@MacBook-Pro bachelor %
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
# lunar3.py header
from wordcloud import WordCloud
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
#lunar4.py header
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
# lunar5.py header
from sklearn.model_selection import GridSearchCV
from sklearn.decomposition import LatentDirichletAllocation as LDA
#lunar1.py
text_paths = glob.glob('data/text/**/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
text = text.split('\n')
title = text[2]
text = ' '.join(text[3:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
# display(processed_news_ss.head())
# lunar3.py
font_path="/Library/Fonts/ipaexg.ttf"
font_property = matplotlib.font_manager.FontProperties(fname=font_path, size=24)
# font_property = matplotlib.font_manager.FontProperties(size=24)
def show_wordcloud(series):
long_string = ','.join(list(series.values))
# Create a WordCloud object
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# wordcloud = WordCloud( background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# Generate a word cloud
wordcloud.generate(long_string)
# Visualize the word cloud
plt.imshow(wordcloud)
plt.show()
# show_wordcloud(processed_news_ss)
# lunar4.py
count_vectorizer = CountVectorizer()
count_data = count_vectorizer.fit_transform(processed_news_ss)
tfidf_vectorizer = TfidfTransformer()
tfidf_data = tfidf_vectorizer.fit_transform(count_data)
# print(tfidf_data.toarray())
# print(tfidf_data.shape)
# lunar5.py
def gridsearch_best_model(tfidf_data, plot_enabled=True):
# Define Search Param
n_topics = [4,5,6,7,8,9]
search_params = {'n_components': n_topics}
# Init the Model
lda = LDA(max_iter=25, # Max learning iterations
learning_method='batch',
random_state=0, # Random state
n_jobs = -1, # Use all available CPUs)
)
# Init Grid Search Class
model = GridSearchCV(lda, param_grid=search_params)
# Do the Grid Search
model.fit(tfidf_data)
# Best Model
best_lda_model = model.best_estimator_
# Model Parameters
print("Best Model's Params: ", model.best_params_)
# Log Likelihood Score
print("Best Log Likelihood Score: ", model.best_score_)
# Perplexity
print("Model Perplexity: ", best_lda_model.perplexity(tfidf_data))
# Get Log Likelyhoods from Grid Search Output
log_likelyhoods_score = [round(score) for score in model.cv_results_["mean_test_score"]]
if plot_enabled:
# Show graph
plt.figure(figsize=(12, 8))
plt.plot(n_topics, log_likelyhoods_score)
plt.title("Choosing Optimal LDA Model")
plt.xlabel("Numer of Topics")
plt.ylabel("Log Likelyhood Scores")
plt.show()
return best_lda_model
best_lda_model = gridsearch_best_model(tfidf_data)
# lunar6.py
def print_topics(model, count_vectorizer, n_top_words):
fig = plt.figure(figsize=(15,8))
words = count_vectorizer.get_feature_names()
for topic_idx, topic in enumerate(model.components_):
print("\nTopic #", topic_idx, ":")
long_string = ','.join([words[i] for i in topic.argsort()[:-n_top_words - 1:-1]])
print(long_string)
topic_wordcloud(topic_idx, fig, long_string)
# show plots
fig.tight_layout()
fig.show()
def topic_wordcloud(topic_idx, fig, long_string):
ax = fig.add_subplot(2, 3, topic_idx + 1)
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
wordcloud.generate(long_string)
ax.imshow(wordcloud)
ax.set_title('Topic '+str(topic_idx))
number_words = 500
print_topics(best_lda_model, count_vectorizer, number_words)
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
# lunar3.py header
from wordcloud import WordCloud
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
#lunar4.py header
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
# lunar5.py header
from sklearn.model_selection import GridSearchCV
from sklearn.decomposition import LatentDirichletAllocation as LDA
#lunar1.py
text_paths = glob.glob('data/text/**/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
text = text.split('\n')
title = text[2]
text = ' '.join(text[3:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
# display(processed_news_ss.head())
# lunar3.py
font_path="/Library/Fonts/ipaexg.ttf"
font_property = matplotlib.font_manager.FontProperties(fname=font_path, size=24)
# font_property = matplotlib.font_manager.FontProperties(size=24)
def show_wordcloud(series):
long_string = ','.join(list(series.values))
# Create a WordCloud object
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# wordcloud = WordCloud( background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# Generate a word cloud
wordcloud.generate(long_string)
# Visualize the word cloud
plt.imshow(wordcloud)
plt.show()
# show_wordcloud(processed_news_ss)
# lunar4.py
count_vectorizer = CountVectorizer()
count_data = count_vectorizer.fit_transform(processed_news_ss)
tfidf_vectorizer = TfidfTransformer()
tfidf_data = tfidf_vectorizer.fit_transform(count_data)
# print(tfidf_data.toarray())
# print(tfidf_data.shape)
# lunar5.py
# def gridsearch_best_model(tfidf_data, plot_enabled=True):
def gridsearch_best_model(tfidf_data, plot_enabled=False):
# Define Search Param
n_topics = [4,5,6,7,8,9]
search_params = {'n_components': n_topics}
# Init the Model
lda = LDA(max_iter=25, # Max learning iterations
learning_method='batch',
random_state=0, # Random state
n_jobs = -1, # Use all available CPUs)
)
# Init Grid Search Class
model = GridSearchCV(lda, param_grid=search_params)
# Do the Grid Search
model.fit(tfidf_data)
# Best Model
best_lda_model = model.best_estimator_
# Model Parameters
print("Best Model's Params: ", model.best_params_)
# Log Likelihood Score
print("Best Log Likelihood Score: ", model.best_score_)
# Perplexity
print("Model Perplexity: ", best_lda_model.perplexity(tfidf_data))
# Get Log Likelyhoods from Grid Search Output
log_likelyhoods_score = [round(score) for score in model.cv_results_["mean_test_score"]]
if plot_enabled:
# Show graph
plt.figure(figsize=(12, 8))
plt.plot(n_topics, log_likelyhoods_score)
plt.title("Choosing Optimal LDA Model")
plt.xlabel("Number of Topics")
plt.ylabel("Log Likelyhood Scores")
plt.show()
return best_lda_model
best_lda_model = gridsearch_best_model(tfidf_data)
# lunar6.py
def print_topics(model, count_vectorizer, n_top_words):
fig = plt.figure(figsize=(15,8))
words = count_vectorizer.get_feature_names()
for topic_idx, topic in enumerate(model.components_):
print("\nTopic #", topic_idx, ":")
long_string = ','.join([words[i] for i in topic.argsort()[:-n_top_words - 1:-1]])
print(long_string)
topic_wordcloud(topic_idx, fig, long_string)
# show plots
fig.tight_layout()
fig.show()
def topic_wordcloud(topic_idx, fig, long_string):
ax = fig.add_subplot(2, 3, topic_idx + 1)
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
wordcloud.generate(long_string)
ax.imshow(wordcloud)
ax.set_title('Topic '+str(topic_idx))
number_words = 500
# print_topics(best_lda_model, count_vectorizer, number_words)
# lunar7.py
test_data_ss = pd.Series(['このクリームの成分', 'このパソコンの性能が良い'])
processed_test_data_ss = preprocess_jp(test_data_ss)
test_count_data = count_vectorizer.transform(processed_test_data_ss)
test_tfidf_data = tfidf_vectorizer.transform(test_count_data)
doc_topic_mat = best_lda_model.transform(test_tfidf_data)
dominant_topic = np.argmax(doc_topic_mat, axis=1)
test_data_df = pd.DataFrame(test_data_ss, columns=['text'])
test_data_df['topic_id'] = dominant_topic
display(test_data_df)
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar1.py
text_paths = glob.glob('data/ocu2/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
# text = text.split('\n') # modified
text = text.split(',')
title = text[3] # added
# title = text[2] # modified
text = ' '.join(text[8:])
texts.append(text)
news_ss = pd.Series(texts)
display(news_ss.head())
# display(news_ss)
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
# lunar1.py
text_paths = glob.glob('data/ocu2/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
# text = text.split('\n') # modified
text = text.split(',')
title = text[3] # added
# title = text[2] # modified
text = ' '.join(text[8:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# display(news_ss)
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
display(processed_news_ss.head())
# display(processed_news_ss)
# フォントの入手元 https://moji.or.jp/ipafont/ipafontdownload/
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
# lunar3.py header
from wordcloud import WordCloud
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
#lunar1.py
text_paths = glob.glob('data/ocu2/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
# text = text.split('\n') # modified
text = text.split(',')
title = text[3] # added
# title = text[2] # modified
text = ' '.join(text[8:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
# display(processed_news_ss.head())
# lunar3.py
font_path="/Library/Fonts/ipaexg.ttf"
font_property = matplotlib.font_manager.FontProperties(fname=font_path, size=24)
# font_property = matplotlib.font_manager.FontProperties(size=24)
def show_wordcloud(series):
long_string = ','.join(list(series.values))
# Create a WordCloud object
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# wordcloud = WordCloud( background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# Generate a word cloud
wordcloud.generate(long_string)
# Visualize the word cloud
plt.imshow(wordcloud)
plt.show()
show_wordcloud(processed_news_ss)
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
# lunar3.py header
from wordcloud import WordCloud
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
#lunar4.py header
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
# lunar1.py
text_paths = glob.glob('data/ocu2/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
# text = text.split('\n') # modified
text = text.split(',')
title = text[3] # added
# title = text[2] # modified
text = ' '.join(text[8:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
# display(processed_news_ss.head())
# lunar3.py
font_path="/Library/Fonts/ipaexg.ttf"
font_property = matplotlib.font_manager.FontProperties(fname=font_path, size=24)
# font_property = matplotlib.font_manager.FontProperties(size=24)
def show_wordcloud(series):
long_string = ','.join(list(series.values))
# Create a WordCloud object
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# wordcloud = WordCloud( background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# Generate a word cloud
wordcloud.generate(long_string)
# Visualize the word cloud
plt.imshow(wordcloud)
plt.show()
# show_wordcloud(processed_news_ss)
# lunar4.py
count_vectorizer = CountVectorizer()
count_data = count_vectorizer.fit_transform(processed_news_ss)
tfidf_vectorizer = TfidfTransformer()
tfidf_data = tfidf_vectorizer.fit_transform(count_data)
print(tfidf_data.toarray())
print(tfidf_data.shape)
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
# lunar3.py header
from wordcloud import WordCloud
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
#lunar4.py header
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
# lunar5.py header
from sklearn.model_selection import GridSearchCV
from sklearn.decomposition import LatentDirichletAllocation as LDA
#lunar1.py
text_paths = glob.glob('data/ocu2/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
# text = text.split('\n') # modified
text = text.split(',')
title = text[3] # added
# title = text[2] # modified
text = ' '.join(text[8:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
# display(processed_news_ss.head())
# lunar3.py
font_path="/Library/Fonts/ipaexg.ttf"
font_property = matplotlib.font_manager.FontProperties(fname=font_path, size=24)
# font_property = matplotlib.font_manager.FontProperties(size=24)
def show_wordcloud(series):
long_string = ','.join(list(series.values))
# Create a WordCloud object
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# wordcloud = WordCloud( background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# Generate a word cloud
wordcloud.generate(long_string)
# Visualize the word cloud
plt.imshow(wordcloud)
plt.show()
# show_wordcloud(processed_news_ss)
# lunar4.py
count_vectorizer = CountVectorizer()
count_data = count_vectorizer.fit_transform(processed_news_ss)
tfidf_vectorizer = TfidfTransformer()
tfidf_data = tfidf_vectorizer.fit_transform(count_data)
# print(tfidf_data.toarray())
# print(tfidf_data.shape)
# lunar5.py
from sklearn.model_selection import GridSearchCV
from sklearn.decomposition import LatentDirichletAllocation as LDA
def gridsearch_best_model(tfidf_data, plot_enabled=True):
# Define Search Param
# n_topics = [4,5,6,7,8,9]
n_topics = [8,9,10,11,12,13]
search_params = {'n_components': n_topics}
# Init the Model
lda = LDA(max_iter=25, # Max learning iterations
learning_method='batch',
random_state=0, # Random state
n_jobs = -1, # Use all available CPUs)
)
# Init Grid Search Class
model = GridSearchCV(lda, param_grid=search_params)
# Do the Grid Search
model.fit(tfidf_data)
# Best Model
best_lda_model = model.best_estimator_
# Model Parameters
print("Best Model's Params: ", model.best_params_)
# Log Likelihood Score
print("Best Log Likelihood Score: ", model.best_score_)
# Perplexity
print("Model Perplexity: ", best_lda_model.perplexity(tfidf_data))
# Get Log Likelyhoods from Grid Search Output
log_likelyhoods_score = [round(score) for score in model.cv_results_["mean_test_score"]]
if plot_enabled:
# Show graph
plt.figure(figsize=(12, 8))
plt.plot(n_topics, log_likelyhoods_score)
plt.title("Choosing Optimal LDA Model")
plt.xlabel("Number of Topics")
plt.ylabel("Log Likelyhood Scores")
plt.show()
return best_lda_model
best_lda_model = gridsearch_best_model(tfidf_data)
(bachelor) user@MacBook-Pro bachelor % python3 ocu123456.py
File already exists.
Best Model's Params: {'n_components': 10}
Best Log Likelihood Score: -57286.863089259525
Model Perplexity: 3495.2774341479862
Topic # 0 :
ループ,検知,泉井,ダウン,閉塞,シャット,配下,眞佐子,くん,森本,外科,歯科,口腔,大黒,自動,泰成,幸田,佐賀,筑波大,アーカイブ,赴任,セミナー,毎朝,部内,高井,滋賀大学,飛鳥,トップページ,解除,数学,予備,切替える,余裕,スキャナ,附属,不備,ペイン,ドクター,つかえる,柳本,井口,復帰,溝上,記事,メンバ,はいれる,不正,クローム,古賀,ソフトバンク,後援,達也,問合せ,静愛,直樹,もとづく,ハイブリット,ゲストハウス,石神,給付,正式,光成,買い替える,亀田,小川,ヤマモト,マキタ,生里,始業,平素,偏る,聞き出す,植松,たける,分ける,心当たり,好ましい,ウインドウ,小塚,無給,授与,模様,倫理,去年,ゆるい,関田,ストレージ,幹線,赤色,マック,思い違い,高塚,いじる,さし,折れる,少数,ピクセル,正方形,枝里子,中台,あむ,免疫,配付,遅れる,割り込み,国外,直前,ゲノム,気づく,インチ,きたす,引ける,西浦,企業,しれる,勤怠,中島,洋司,浅井,作動,剛史,所定,もつ,ずれ込む,取り込める,ファイルサイズ,湯口,大樹,裕朗,玉井,美香,競合,返送,ウエダ,知幸,とれる,ども,宮本,左記,かなう,邪魔,おこなう,推定,お気に入り,抜染,まずい,刺す,パート,マンツーマン,冨澤,あおい,ボス,ピーク,基板,未帆,スタンス,望ましい,晴恵,果たす,部門,臨地,結合,カワサキ,肩書,迅速,埋める,差し込む,伏せる,勝手,解る,受け持つ,カラ,ともなう,タイ,お陰様,ポインター,ペン,貰える,紘子,老年,逼迫,立て込む,特筆,悩み,ゴールデンウィーク,みあたる,繋がり,出せる,加工,生産,直接アクセス,エンジニア,給湯,同居,正行,公共,無知,慎重,一室,組み換え,早朝,弊社,退社,重視,時差,全課,国文学,糀谷,多恵子,代打,混雑,三宅,件数,国語,端子,枠組み,開放,取り消し,高齢,新調,及ぶ,旅行,鹿毛,まち,手間取る,引用,右往左往,ベスト,夏期,近畿大学,作り,うる,加筆,なおこ,うの,書き直し,バックス,合わさる,先だって,潜在,中止,明記,ペース,余計,遮断,存じ上げる,締め切り,明細,オン,目標,病院,受入れ,弘之,支社,ロケーション,備わる,統括,曰く,2月,お断り,図れる,達成,学び,関わり,実践,4つ,アカ,コミュニケーション,最低限,日数,目安,開講,独立,構成,うえ,探し出す,回数,観察,我慢,取り外す,取り除く,今津,しなす,途切れる,転記,たどり着く,立てる,繰り返し,申告,広報,普段,分かれる,とる,問いあわせる,八千代,日時,タグ,静的,ご多忙,連続,切り替える,学位,スルー,立て続け,不可欠,掃除,9月,浮く,とまる,上位,整理,益田,受け入れる,松浦,取りまとめ,抜き,石原,ストーム,項目,持ち帰り,番号,理系,のる,専任,深刻,文系,山尾,重度,株式会社,ブロードキャスト,許可,重なる,ホール,防ぐ,時刻,お手伝い,満つ,向かう,えり,セッション,人間,研究所,答える,福祉,台風,川合,再発,むける,広岡,連動,文教,兼ねる,上限,山岡,下さる,換え,リアルタイム,事情,抜く,受入,宜しい,医学部,かす,速やか,羽下,由紀子,上昇,打ち合わせる,キュー,言う,埋め込む,形跡,組む,規模,信頼,頻度,半分,脅威,不便,実習,低下,サイズ,構造,当課,変える,石橋,指名,亮輔,多発,差す,ジャーナル,則る,中央,ご存知,解消,相当,止まる,疑う,無題,あわせる,要因,主催,バック,保障,終了,いる,カーソル,休暇,スイッチ,超過,添付,フロア,安定,操作,早々,弾く,整形,購読,超える,データ,ルーム,時半,おりる,けんか,だける,忠雄,差し替える,振替,残念,池端,コン,引継ぎ,ミス,環境,判断,引き続く,保持,上述,ダウンロード,点く,差し上げる,講座,充てる,富士ゼロックス,親子,笠川,配線,佐藤,掴む,書き込み,コンセント,申し上げる,差替え,クイック,電話,拒否,制度,控える,お世話,産業,メモリ,返る,詳細,先程,なし,西口,ポート,大変,女性,裏手,谷川,客員,過ぎ,含める,川上,合わせ,ドラッグ,やり取り,物理,どなた,キーボード,バグ,程度,監視,営業,阿部,先生,張る,ショートカット,ダイバー,酒井,マウス,分配,支援,上田,直後,厳しい,目的,途中,メディア
Topic # 1 :
記念,聡美,原田,晴美,中野,村上,固まる,植物,数式,英数字,高原,全角,白い,美緒,選考,ハイフン,ホール,小文字,広岡,京都大,発信,株式会社,渡辺,持田,大文字,附属,エディター,半年,一志,江川,ブラック,論文,アップル,メリット,折返し,中田,貸出,スポーツ,森下,小畑,理紗,森内,こみあう,敏之,混雑,黒文字,茶畑,里奈,神山,森原,小泉,題名,エンド,分類,各社,ローマ字,耕一,ヘッダ,絞る,デメリット,渡し,県立,兵庫,思い出す,代行,保留,ヒット,前日,中原,課外,立ち会い,和人,イベント,菅原,流出,ついで,海渡,一昨年,対面,払出し,澄子,反対,蓄積,直接アクセス,結線,誕生,上位,古澤,スイッチ,橋本,委譲,地名,礼実,簡易,廣川,法医学,集線,依子,西脇,岩熊,譲り受ける,職人,ビル,駅前,祐加,奈緒,見え,紛失,切れ,透過,取り,宏子,英子,いづみ,おちる,まちがい,とたん,検出,立ち会う,寄る,出かける,ノウハウ,パッチ,雨宮,打つ,タイプ,号機,角南,貴司,江原,省一,協定,藤原,臨む,帳票,ターム,淑子,12月,貯まる,折れる,キュー,しなす,差し,配慮,つめ,統括,ひさし,助ける,日経新聞,リターン,バッファ,高所,エア,インテリジェント,ステーション,集計,部門,秘匿,コツ,範囲,まわす,浩志,問診,屋外,郁朗,確度,訪れる,おしらせ,高校生,差し込み,佳奈,坪田,救出,岩見,達也,哲治,火曜日,数個,シモ,ナカ,森脇,簡素,寛人,間に合う,労使,乗り換え,だいたい,高校,来客,次週,学術情報センター,振興,昭子,寺岡,話し合い,江梨,半角,離任,新設,渡す,来年,コミュニケーション,ゆくゆく,水曜,文句,関する,困窮,要項,狩俣,手つかず,募集,みなす,千博,選任,日比野,ホワイト,老朽,終業,間際,今日,給付,コスト,分野,秀之,退出,競合,放つ,高齢,読み取る,桃子,統一,行宏,玉造元,天王寺,共栄,つとめる,弁理,商標,特許,十分,最下,大全,あま,対抗,見当,甘い,適う,忘れ物,落とし物,バラバラ,真弓,阿呆,見極め,増田,ブラックリスト,市川,安価,編入,はな,絢子,半月,在住,騒ぎ,関東,お手上げ,離宮,バス,ドレス,いか,おそい,性格,持ち運び,実態,釈然,疑う,メイル,まちまち,用事,充分,兼用,ペース,直人,閉館,入館,折る,半日,労働,置き場,取り組む,広場,付近,脱字,約束,サンド,裁量,要す,受け取り,知らせる,誤字,篤い,うかがう,皆さん,学ぶ,痛感,学業,学友,例える,測定,宇田,専門,中央大学,持ち出し,お陰様,究明,カーソル,拒絶,まじえる,位置づけ,迅速,逸脱,国内外,思いつく,空港,正史,押せる,在学,話し合う,専修,防げる,誤判,下回る,トータルシステム,当てはまる,小野,隠蔽,容認,取り掛かる,カスタマイズ,的確,深謝,空欄,保証,ける,保守,基準,妨害,内外,書き直す,煩雑,知識,ドキュメント,面す,右手,新旧,ガラス張り,正門,企業,いっさい,入口,同等,地図,ひとこと,示唆,黙認,再考,ていねい,まかる,抱える,ゆえ,全国,止む,粘る,いきる,負える,並行,いえる,予測,ユニ,検疫,ロフト,顧客,同席,細長い,挟む,地区,去年,部室,事務所,トレース,予防,嬉しい,強度,発表,入り口,安心,開く,価格,記号,試みる,なおす,建築,うける,ルート,裏口,乗り換える,通行,在る,矢印,金額,赤字,試用,休日,根拠,万全,実状,デー,自室,なくす,洋一,変化,動的,モデル,義成,遮断,騙る,エディション,緊急,消せる,詐称,一点,平成,走る,つかえる,等々,模索,しな,辺り,投げる,転記,願い,書架,ケガ,引っ掛ける,横切る,ざま,うに,騒がせる,再送,取り直す,現行,上部,隔離,判定,漏洩,私用,出力,菜々,年末,移る,今週,松岡,制約,シェア,個々,竹内,もしか,外部,回線,うつす,最長,受け取れる,置き換える,中山,皆様,回収,破損,有無,待ち,呼ぶ,プロ,救命,ポップアップ,つなげる,お詫び,起こす,になう,不手際,まんが,ガイダンス,メンバ,診断,来れる,映す,図書館,木曜日,搭載,久しぶり,名奈,取り扱う,健康
Topic # 2 :
回収,無線,希望,コミュニティ,返却,代替え,不調,篠原,週間,ファームウェア,小久保,芝野,伺い,豊田,坂田,順番,程度,留意,機種,イノベーション,緊急,除く,山中,前後,法学部,眞田,場所,玉巻,清美,貸出,健太,代替,太朗,最新,諸々,明日香,竜馬,視聴,兼田,永友,頂戴,真衣,防犯,エディション,要因,知子,玲奈,品切れ,大友,設置,適応,職種,盛田,事項,板谷,メーカー,福谷,増設,附属,万が一,記入,早智子,部屋,速度,水野,大江,恵子,進捗,上位,たずねる,美幸,限り,ハング,心理,っぱなし,試験,送れる,信一郎,野本,脆弱,レンジ,荻尾,阪大,発表,バージョン,弘美,適用,久保,松浦,断る,小関,彰一,広瀬,パッチ,臨床,アップデート,光永,松井,正治,業務,主張,始め,和文,石崎,唐沢,特殊,川井,つき,光成,つけ,選べる,熊田,文書,分配,本部,広美,富士ゼロックス,誰か,フロア,ブロードキャスト,取り換える,私用,知香,インターン,倫子,不要,前半,クラ,ウド,福田,経験,巻き,オープン,時刻,周り,持ち合わせる,巻く,美智,規程,改正,過日,後々,弓削,良子,米国,学長,くん,二郎,ナガサキ,点く,赤字,森山,越し,ストーム,鳥丸,うかがう,ショー,同居,付近,櫻田,初期,村田,欲しい,第三者,高石,飛ぶ,木曜,ファン,分岐,同等,話し合い,応答,実咲,柏山,質疑,放つ,ドキュメント,やり方,止める,彰宏,就職,波及,組む,便覧,弊害,日数,続く,つたえる,真未,ルーティング,プロジェクタ,事務所,プラグ,かえる,短時間,展子,太田,増強,壊れる,途切れる,調整,張り替える,武井,小畠,同行,拝聴,評価,汐見,石丸,政策,学期,遅れる,在外,小田中,引き渡し,カク,文献,祐太郎,疑い,借りる,如何,祥行,福島,松下,従事,踏襲,見当,ます,来年,小生,割り当て,社員,開講,知宏,id,手近,澤田,健康,智子,達哉,上村,ディスプレイ,滞在,かざす,成績,向ける,レジスト,コミュニティー,むら,復帰,モト,さす,上席,峰子,正則,リコー,拠点,追伸,康平,コンタクト,スロット,つかめる,立ち会い,最短,基子,崩れる,採点,和木,流量,働きかける,並べる,またがる,車両,コン,受け,止まる,思い込む,ng,色々,カウンタ,過程,数多い,安川,眼科,キャビネット,櫛野,オリジナル,もどる,遷移,直之,頼む,差異,ナオ,北山,萩尾,休止,変る,市川,破損,スピーカ,乖離,現状,お断り,問合せ,香恵,ノック,スイッチング,理緒,渡慶次,持ち出せる,宇田,まとめる,育休,推薦,湯浅,切り離し,内蔵,最低限,引く,収集,中原,シュウ,ジン,価格,アルファベット,向かう,常男,美咲,浮く,いえる,保留,上嶋,富田林,津々山台,なを,小さい,片言,小松,登美子,映像,解明,ストップウォッチ,アクション,公衆,三苫,岩見,将来,運動,綴り,金澤,元々,久裕,ピクチャ,ミュージック,ごみ箱,多分,最寄り,電車,辻田,秋本,徹底,気が付く,向上,紙面,栞里,西端,正誤,入社,形態,おる,笹島,未菜,大仁田,開示,干渉,火曜,把握,佐和子,文庫,大宅,けんか,雅美,取り外す,上長,だす,乗越,拓海,似る,保つ,経由,美佳,中前,数回,シフト,通番,整形,欠落,医員,フジイ,ライフサイクル,せん,三菱,宮地,善彦,東條,閉鎖,あらわれる,普段,お返し,そもそも,本務,かう,締め切り,しぼれる,原本,いそぐ,鮮明,見やすい,同席,別々,迅速,ご無沙汰,章浩,靖子,池野,裁量,水原,施錠,迷う,折る,立ち会う,森井,トップページ,シート,静か,天井,端子,眞奈美,英雄,市販,天候,適宜,いたる,なくす,地下,大生,帳票,転記,実態,講読,知らせる,強度,左記,転職,ユニ,規定,やらかす,パック,電池,手すき,特有,やう,問い,見積もり,予測,王様,司書,伴う,任せる,お世話,立て続け,破綻,チャネル,製造元,ささやか,着く,帰路,時折,スライド,受け取り,流れる,4つ,火曜日,僭越,解凍,離れる,カーソル,拝復,通勤,代々,気軽,ばば,ケン,カツ,知らす,各所,先着,当選,発達,足らず
Topic # 3 :
する,認証,障害,接続,システム,教員,できる,無線,復旧,設定,アドレス,相談,プリンタ,起動,問い合わせ,職員,不明,ケーブル,ネットワーク,ログイン,画面,取得,繋がる,なる,表示,使用,ポート,部屋,登録,ログアウト,出来る,変更,学生,サーバ,お伝え,確認,メール,問題,不具合,通信,実施,電源,有線,インターネット,機器,コンセント,解除,依頼,情報,端末,モード,正しい,原因,発生,不良,現地,動作,正常,先生,連絡,失敗,ない,交換,受信,ある,配線,対応,教える,調査,つながる,パスワード,説明,ハブ,プリンター,ブリッジ,誤る,管理,送信,可能,申請,頂く,固定,設置,思う,エラー,印刷,案内,無効,ログ,削除,サポート,行う,状態,出る,切れる,事象,不安定,利用,様子見,有効,セグメント,訪問,送付,故障,使える,グローバル,新規,回答,成功,停電,入力,方式,構成,財務,抜き差し,今朝,購入,居室,理学部,済み,パソコン,プロトコル,試す,工学部,プロファイル,消える,いただく,同様,お願い,結果,会計,手動,サーバー,ネット,伝える,作業,わかる,影響,マニュアル,再発,手順,アクセス,抜ける,現象,残る,研究,払い出す,特定,入る,範囲,切り分け,見る,紹介,カメラ,修正,改善,解決,届く,検証,ホワイト,先方,インストール,阿る,変わる,昨日,ユーザ,ミス,挿す,業者,チェック,経過,外部,コン,隔離,複数,間違い,様子,機能,おかしい,その他,判明,質問,かかる,スプール,貸し出す,あり,会議,ページ,格納,理由,自然,誤り,無し,スパムメール,収容,上手い,物理,戻す,互換,処理,形跡,でる,詳細,到着,送れる,移動,室内,起こす,新しい,払い出し,不可,撤去,サイト,アカウント,フィルタ,外す,最近,うまい,本体,暫定,断線,プライベート,テスト,切り替え,電話,大量,アイテム,古い,タイミング,再現,カスケード,センター,アダプタ,肥大,解放,ヒアリング,全体,飛ぶ,無い,デフォルト,トレイ,ツール,必要,環境,直接,買い替え,落ちる,アダプター,完了,推測,範疇,実行,要す,遅延,ドメイン,本日,西口,現在,不適切,赴任,切り替わる,追加,ロック,メーカー,種別,回避,今後,不在,状況,買い換える,報告,いる,疎通,解消,負荷,問い合わせる,入れる,起こる,通る,頻繁,遮断,全学,無事,繋ぐ,お気に入り,繰り返す,広瀬,更新,リスト,振る,理解,テーブル,現状,開放,新名,立つ,安定,外れる,辻川,抜く,アップ,購読,相性,一部,取れる,異なる,齋藤,振り替える,該当,パケット,ユーザー,学科,一端,無くなる,実験,仮想,変える,先週,差し替える,消せる,判定,検討,拒否,マシン,スクリプト,対象,導入,もらえる,回収,接触,事務,自動的,見える,頻発,直後,おすすめ,守衛,保持,配属,替える,小笠原,挙動,当該,悪い,組み合わせ,柏木,操作,バージョンアップ,出力,下書き,正樹,高い,作成,リンク,起きる,間違う,載る,ハード,点灯,勧める,工場,出荷,過去,見直す,初期,インシデント,工事,差す,配送,いく,空き,了承,空く,坪田,経済,経路,予定,変換,メールアドレス,伸びる,川合,次回,遠隔,みる,行く,2つ,通常,提案,スタティック,メッセージ,ワイヤレス,分類,同一,モニター,映る,考える,復活,転送,場所,図面,試行,程度,研究所,入替る,貰う,最後,来る,引き込む,対向,科学,やる,藤田,振り分ける,指定,明け,廊下,エスカレーション,根本,黒松,増やす,地区,三田,推進,移転,臨時,修理,やり直す,組織,推奨,見れる,大学,言う,開ける,空欄,かわく,けいすけ,割り振る,増設,保守,立ち上がる,学内,かける,件数,怪しい,バックアップ,調子,部局,経つ,サービス,もらう,亜紀,後日,助手,印刷物,関数,オプション,求める,つま,久井,違う,通電,施す,ルーティング,大文字,メールボックス,プログラム,出す,判断,認識,対処,覚え,裕光,宛て,関わる,両方,全員,リング,分かる,分散,詐称,光る,しる,超える,閲覧,生活,構造,本館,対策,割り,根拠,リリース,発する,一存,施策,参照,見直し,教務,学外,警報,完全
Topic # 4 :
依頼,物質,コミュニティ,登録,化学,訓練,向け,受講,教職員,取扱,年度,ログイン,クリック,氏名,作業,各自,衛生,安全,コース,研究,教育,大阪市立大学,ホームページ,納品,支援,短縮,基づく,田邉,設定,アナウンス,地球,理学,分子,アカウント,哲朗,技術,回収,小原,動作,無線,持つ,担当,おく,大橋,全学,アクセス,大きい,住吉,職員,いただく,希望,足立,バージョンアップ,生物,公式,経緯,ファームウェア,申し込み,専攻,所属,持ち,パスワード,大阪,参照,収まる,杉本,エミ,完了,オリジン,野村,別物,実験,堀井,弥生,久末,奈津子,買い替える,認証,フォロー,行う,代香,宍戸,付け替える,設置,一孝,タブレット,定型,裕子,生体,電話機,管理,フォント,渡邊,検査,剛史,招聘,基礎,分野,キャノン,恭代,教員,吉里,学生,先端,部門,減少,連休,ためし,いただける,コンテキスト,皆谷,榎並,新調,設立,する,競合,停滞,内藤,押せる,新設,取り違える,宣行,もろもろ,軽い,意表,貴子,守矢,里佳,補佐,キヤノン,増設,上位,真宏,坂本,昼休み,だす,にる,止まる,英雄,構造,オーディオ,メイル,切り離せる,オリジナル,引き継ぎ,宇田,島村,満里子,ap,販売元,製図,不通,特有,確認,設計,直通,千恵,改行,勝利,千代美,手書き,ある,川倉,紀彦,防災,領域,田丸,植松,お世話,増田,利用,浩志,撤退,ヘルプ,飽和,専属,美香,約束,寿一,黒板,中島,背面,当時,敏也,幸隆,デスク,灰色,記号,製品,ひとまず,おしえる,募金,ヤナギ,元年,基金,発言,特徴,シーン,委ねる,吉川,藤森,呼び出し,受話器,理想,クリップ,平成,裕紀子,ボード,入り組む,鳴る,エンタープライズ,卒業生,池上,統一,年明け,歯車,宮下,神経,具合,内科,間近,兼務,なる,医局,識別,しがらみ,転換,奈美子,発信,拝復,なぜだか,拍子抜け,12月,関山,受発信,たかこ,しずか,健一,イラストレーター,困惑,ガイドブック,包含,吉良,破損,性能,もみ,ふじ,あて,増加,発令,中心,手こずる,固まる,山家,書架,ケガ,横切る,引っ掛ける,お願い,拝借,頼む,田邊,玉井,レーザー,量子,オープン,代物,しょうが,かなう,地盤,走る,チャット,対話,中辻,いか,議員,つけ,監視,除外,陽一郎,南部,お陰様,測定,三宅,映像,在学,古谷,読み替える,安心,民間,声明,隣接,松美,悪化,思わしくない,案内,清二,智美,貴様,宗一,芳紀,堀越,前川,解析,佳い,幹事,由紀,中沢,促進,本道,まえる,波動,b5,福永,村田,利夫,佳彦,生理学,繁行,加工,生産,一案,先頭,バス,実態,関田,鹿毛,長澤,元素,差し戻し,懇談,講習,藤巻,集団,分析,迷う,谷本,橋本,幸一,益田,晴恵,お互い,名簿,高等,委員,高齢,美輪子,スクリプト,佐伯,洋司,アレンジ,人口,高分子,後援,石川,代用,茂喜,逓送,貼付,亜紀,内線,黒松,生里,つながり,小宮,関西,正樹,かおり,松山,知幸,中台,枝里子,ヘリウム,液化,小池,ガラス,気がつく,状況,点く,植物,村島,下中,工作,重たい,紛らわしい,慣れる,足す,文教,付箋,神谷,昇格,美紗,泰子,附属,事業,複合,除去,厳しい,宇野,理恵,出力,問う,出口,施設,亀田,食品,細胞,同一,和美,空欄,サンプル,済み,博士,思える,記す,湯浅,理学部,物理,保持,寺田,ディレクトリ,数字,家庭,受ける,敏之,点滅,市立,森内,間に合う,代表,武田,期待,切り替える,長倉,講座,川上,工学,都市,本学,うごく,秘書,機構,広い,シール,栄養,早め,和田,ご多忙,下位,大学院,除く,取り出す,動物,日出雄,光合成,直子,要因,割当てる,解凍,比べる,葉子,故障,同室,お話し,機能,人工,健康,公立大,岡崎,日々,学科,申告,ヨシダ,最大,電子,田中,ついで,かた,価格,連携,趣旨,相談,協議,取り扱い,盗む,お詫び,問い合わせ,絶対,フロー,テンプレート,携帯,漏れ,別室,貸し,付属,宜しい,聡美,稼働,さま,数学
Topic # 5 :
プリンタ,複合,印刷,する,プリンター,ネットワーク,仮想,登録,申請,アドレス,システム,問い合わせ,教員,できる,相談,グローバル,ログイン,説明,追加,ホーム,使用,ゼロックス,職員,移行,許可,学生,出力,先生,人事,認証,研究,ドライバー,管理,プライベート,設定,新しい,設置,依頼,石本,支援,自動,事務,指定,教える,変更,村岡,メンバー,案内,オフライン,移設,ない,切替,経緯,号館,松本,なる,作業,割り当てる,お伝え,テレビ,障害,アクセス,院生,つける,送付,小林,端末,コピー,故障,必要,通信,疎通,入れ替え,インストール,会議,付き,回答,異動,参照,本体,お願い,権限,梅田,入れ替える,共同,入試,就職,更新,九鬼,確認,保全,正しい,雅嗣,運用,切り替える,いただく,哲子,接続,機器,真由美,ある,変わる,広岡,人工,友代,電話,給与,山上,効果,居室,工学部,一郎,問題,移動,地球,テーマ,先端,使い方,付ける,舟川,サテライト,新規,手順,生物,よい,機構,藤原,橋本,理学部,図書,阪本,購入,テスト,ログアウト,川井,ヒアリング,番号,瀬川,佐官,思う,無し,いける,可能,緒方,部屋,入れ替わる,ストレージ,本部,伝える,パソコン,裕光,富士ゼロックス,共有,謙一,操作,見える,上述,美津江,ノート,学修,野口,所属,環境,プロ,付与,質問,受け入れ,とれる,プリント,与える,キシ,印字,はじく,発信,機種,制限,サーバ,誤り,羽生,かける,適切,学籍,家族,受け入れる,異なる,いらっしゃる,実施,伴う,法学部,学部,神田,普段,検索,着任,否認,統合,あやまる,五十嵐,りう,ルート,口頭,属する,最終,配置,使える,持つ,以外,買い替える,おしえる,午前,任せる,金森,吉野,コニカ,取得,作成,個々,解析,渡す,機械,研修,土肥,独立,利用,ご存じ,嶋本,属す,成松,大塚,聞く,バイオ,孝一,三洋,山崎,大学入試センター,一輝,順子,情報,お答え,マニュアル,形態,モノクロ,個人,事前,スケジュール,間違う,水口,留学生,所望,厚生,サポート,場所,返送,出来る,来る,記憶,佐竹,切り離す,装置,未登録,委譲,雅人,所在地,正一,自己,欲しい,暗い,生田,ユーザ,生徒,対応,両方,知る,引越し,監視,成美,安心,まとめる,湯浅,資料,皆様,修理,ふつう,現在,取り外す,常勤,化学,長崎,連絡,失念,高い,温度,実央,在学,用途,返る,英輔,了解,該当,深水,ステータス,通る,非常勤,分ける,文学部,振る,停電,今年度,光合成,職種,理乃,整える,寺澤,弾く,河村,複数,ポート,大城,置く,調査,今日,克昭,最新,起票,目安,撮る,会員,基幹,使う,ファイル,あきらめる,予定,大阪大学,理事,絵理子,メール,内容,行う,建屋,久美子,受入れる,ワード,いる,勝手,不審,固定,健史,対象,中台,生える,水谷,導入,推進,完了,違う,横山,所管,博史,モニタ,探せる,中旬,無い,代わる,識別,不一致,付随,奨学,森山,設備,山口,回数,基子,おこなう,使い分け,植村,宮下,厚志,加奈,宇野,理恵,明日,お陰様,アサイン,存在,発注,松野,横浜市大,英一,ドキュメント,遅い,迎える,ササキ,経由,大学,同室,克明,付箋,対向,今更,教授,自前,破損,アクセサリ,期間,年度,映像,来客,気がつく,認識,解像度,智也,不要,不十分,ドット,杉本,出る,ルーム,変動,かかる,望ましい,大型,入れる,みつける,主催,文字,綾乃,正晃,スキャナー,号機,金曜,川嶋,後日,当該,顔ぶれ,昇子,英喜,うまい,櫻木,クス,集計,単体,尚夫,工作,含める,由紀子,解釈,部長,恐れ,オリジナル,究明,アドホック,インフラストラクチャー,来年度,お気づき,セグメント,代理,2月,明細,インプット,正式,実務,楠本,株式会社,流用,神谷,お断り,増える,会う,受入,必須,取りまとめ,書き,藤本,続報,設計,改革,客員,通知,プリン,平等,シマ,ブラックリスト,ハイフン,スタンス,後援,律子,多田,部署,中村,宇高,標題,余計,技能,要請,園枝,切り替わる,ターミナル,構造,康子,早い
Topic # 6 :
中尾,画面,憲一,する,アプリケーション,動画,アイコ,渡邊,セキュリティー,スイッチ,建築,ヘルプ,表示,証明,写真,おかけいたす,プラン,デスク,西野,簡単,なる,安否,お願い,ページ,小檜山,いただける,許可,スクリーン,ショット,サイン,閲覧,お世話,問い合わせ,続行,石堂,アウト,お送り,お手数,プライバシー,川田,バー,左側,書く,状況,セキュリティ,理学,一般,上部,赤丸,選択肢,雄一郎,選択,女性,エラー,工学部,マーク,松倉,ガイド,尾島,衛生,本学,みれる,設定,学科,教員,和恵,メニュー,弓場,現時点,バージョン,ソフト,確認,俊子,警告,インストール,良い,添える,しれる,塩川,環境,伊原,高等,対処,宮田,下崎,黒い,よし,止まる,フォーム,雅美,三船,奈々,辿る,安全,すすむ,時刻,沿う,題名,保護,治代,個人,できる,いただき,裕子,教示,その他,研究,メール,原木,昨夜,下田,利用,付属,マニュアル,文科,英里,スライド,取り直す,手順,クリック,身分,小林,項目,ショー,遠隔,明記,内線,情報,企業,直子,でる,検査,即答,専有,記録,伊藤,森田,津田,江村,服部,名古屋大学,画像,由紀子,上長,フロア,恐れ入る,全額,佳代子,薮崎,頂ける,随時,差出人,進める,信昭,ござる,立てる,システム,変動,浦野,丸山,フラグ,将来,中島,佐知子,所属,真人,つくる,亜希子,長倉,取り消し,曽我,宜しい,先ほど,提案,タップ,行う,移管,サイト,選ぶ,ない,内容,存する,指導,追伸,左記,相談,貸出,読み替える,さゆり,バージョンアップ,常勤,ふる,昇一,脇本,竹田,重要,負荷,ログイン,寺西,存じる,ルック,使い方,右端,夕葉,云々,半分,使用,番号,下さる,バッティング,プロジェクト,水田,地図,通す,細胞,送信,当方,俊也,足す,カウンセラー,掲示板,とのこ,増井,ポップアップ,最新,華子,日原,若森,換え,地区,戴く,仁郎,騒がせる,飛ぶ,間に合う,タイトル,裕己,生物,図書館,康一,含む,わかる,ディレクトリ,包括,植物,竹谷,矢田,清重,解決,ライセンス,標題,授業,経営,久保,書き,中橋,千代子,医局,別府,保証,よろしい,きょう,孝昌,ダウンロード,杉原,リンク,高梨,分類,主幹,払う,該当,貴校,分館,満つ,職員,適当,兼ねる,検収,連絡,立花,スタート,介す,動物,和也,藤川,可能,脇田,ゼロ,破棄,大きい,扱う,康夫,畠中,主催,エン,トランス,論文,容量,健司,忘れ,初期,おき,返信,上司,他人,無視,村田,否認,なりすます,草生,信二,委任,実行,赤字,新人,曽田,保有,助ける,結構,病態,辰郎,打診,入力,末尾,名波,章江,生理学,通り,届け出,詳しい,適正,千尋,流れる,富澤,gb,hp,web,家族,就職,荒井,検討,イン,インターネット,アクセス,石橋,買い替える,リアルタイム,成績,締め切り,ナンバー,差し替え,渡す,付け加える,理学部,ゆえ,オフィス,佳世,区域,取り消す,連動,ロード,移譲,入居,流す,動き,当人,施錠,小宮,些細,久嗣,各人,差し替える,熊本,リコー,契約,手引き,良治,産婦人科,全文,パスワード,ターミナル,蓄積,日野,別々,辻岡,アンダーライン,疎い,張り付ける,アップ,自宅,奈央子,竹下,白田,担当,内山,ある,解る,エンドウ,書店,肝胆,志津子,白藤,答える,修了,コンソール,ブラウザー,徳山,ドロップ,鍵谷,くっつく,ドイツ,文字数,響子,川崎,つきあい,東海林,医療,光希,マスキング,卒業生,知識,未読,プラットフォーム,まじる,払い出し,圧迫,医学,退室,レスポンス,ミニ,連続,改善,遠い,延びる,スタイル,今日,劣化,化け,エラーコード,岩川,良浩,茂喜,教材,文系,新谷,ウィンドウ,不明,アクション,撮影,駆除,すい,なれる,小西,満たせる,火曜日,奥村,短時間,実施,八千代,アマゾン,手前,規約,理系,山村,補完,機材,英子,文書,渡辺,ポインタ,吉川,手伝う,大まか,オン,動的,学内,押下,望み,充彦,参照,不安定,フォーラム,納品,アップデート,英数字,幸美,発生,英文,ロシア,諒子,浦上,案内,添付,黒岩,ウインドウ,吉良,兼務,受け入れる,品質,曽部
Traceback (most recent call last):
File "/Users/user/bachelor/ocu123456.py", line 187, in <module>
print_topics(best_lda_model, count_vectorizer, number_words)
File "/Users/user/bachelor/ocu123456.py", line 174, in print_topics
topic_wordcloud(topic_idx, fig, long_string)
File "/Users/user/bachelor/ocu123456.py", line 180, in topic_wordcloud
ax = fig.add_subplot(2, 3, topic_idx + 1)
File "/Users/user/bachelor/lib/python3.9/site-packages/matplotlib/figure.py", line 1402, in add_subplot
ax = subplot_class_factory(projection_class)(self, *args, **kwargs)
File "/Users/user/bachelor/lib/python3.9/site-packages/matplotlib/axes/_subplots.py", line 39, in __init__
self._subplotspec = SubplotSpec._from_subplot_args(fig, args)
File "/Users/user/bachelor/lib/python3.9/site-packages/matplotlib/gridspec.py", line 689, in _from_subplot_args
raise ValueError(
ValueError: num must be 1 <= num <= 6, not 7
# import IPython
from IPython.display import display
# lunar1.py header
import pandas as pd
import glob
# lunar2.py header
import MeCab
tagger = MeCab.Tagger("-Ochasen")
import mojimoji
import os
import urllib
# lunar3.py header
from wordcloud import WordCloud
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
#lunar4.py header
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
# lunar5.py header
from sklearn.model_selection import GridSearchCV
from sklearn.decomposition import LatentDirichletAllocation as LDA
#lunar1.py
text_paths = glob.glob('data/ocu2/*.txt')
texts = []
for text_path in text_paths:
text = open(text_path, 'r').read()
# text = text.split('\n') # modified
text = text.split(',')
title = text[3] # added
# title = text[2] # modified
text = ' '.join(text[8:])
texts.append(text)
news_ss = pd.Series(texts)
# display(news_ss.head())
# lunar2.py
def load_jp_stopwords(path="data/jp_stop_words.txt"):
url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt'
if os.path.exists(path):
print('File already exists.')
else:
print('Downloading...')
urllib.request.urlretrieve(url, path)
return pd.read_csv(path, header=None)[0].tolist()
def preprocess_jp(series):
stop_words = load_jp_stopwords()
def tokenizer_func(text):
tokens = []
node = tagger.parseToNode(str(text))
while node:
features = node.feature.split(',')
surface = features[6]
if (surface == '*') or (len(surface) < 2) or (surface in stop_words):
node = node.next
continue
noun_flag = (features[0] == '名詞')
proper_noun_flag = (features[0] == '名詞') & (features[1] == '固有名詞')
verb_flag = (features[0] == '動詞') & (features[1] == '自立')
adjective_flag = (features[0] == '形容詞') & (features[1] == '自立')
if proper_noun_flag:
tokens.append(surface)
elif noun_flag:
tokens.append(surface)
elif verb_flag:
tokens.append(surface)
elif adjective_flag:
tokens.append(surface)
node = node.next
return " ".join(tokens)
series = series.map(tokenizer_func)
#---------------Normalization-----------#
series = series.map(lambda x: x.lower())
series = series.map(mojimoji.zen_to_han)
return series
processed_news_ss = preprocess_jp(news_ss)
# display(processed_news_ss.head())
# lunar3.py
font_path="/Library/Fonts/ipaexg.ttf"
font_property = matplotlib.font_manager.FontProperties(fname=font_path, size=24)
# font_property = matplotlib.font_manager.FontProperties(size=24)
def show_wordcloud(series):
long_string = ','.join(list(series.values))
# Create a WordCloud object
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# wordcloud = WordCloud( background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
# Generate a word cloud
wordcloud.generate(long_string)
# Visualize the word cloud
plt.imshow(wordcloud)
plt.show()
# show_wordcloud(processed_news_ss)
# lunar4.py
count_vectorizer = CountVectorizer()
count_data = count_vectorizer.fit_transform(processed_news_ss)
tfidf_vectorizer = TfidfTransformer()
tfidf_data = tfidf_vectorizer.fit_transform(count_data)
# print(tfidf_data.toarray())
# print(tfidf_data.shape)
# lunar5.py
def gridsearch_best_model(tfidf_data, plot_enabled=False):
# Define Search Param
n_topics = [8,9,10,11,12,13]
# n_topics = [4,5,6,7,8,9]
search_params = {'n_components': n_topics}
# Init the Model
lda = LDA(max_iter=25, # Max learning iterations
learning_method='batch',
random_state=0, # Random state
n_jobs = -1, # Use all available CPUs)
)
# Init Grid Search Class
model = GridSearchCV(lda, param_grid=search_params)
# Do the Grid Search
model.fit(tfidf_data)
# Best Model
best_lda_model = model.best_estimator_
# Model Parameters
print("Best Model's Params: ", model.best_params_)
# Log Likelihood Score
print("Best Log Likelihood Score: ", model.best_score_)
# Perplexity
print("Model Perplexity: ", best_lda_model.perplexity(tfidf_data))
# Get Log Likelyhoods from Grid Search Output
log_likelyhoods_score = [round(score) for score in model.cv_results_["mean_test_score"]]
if plot_enabled:
# Show graph
plt.figure(figsize=(12, 8))
plt.plot(n_topics, log_likelyhoods_score)
plt.title("Choosing Optimal LDA Model")
plt.xlabel("Number of Topics")
plt.ylabel("Log Likelyhood Scores")
plt.show()
return best_lda_model
best_lda_model = gridsearch_best_model(tfidf_data)
# lunar6.py
def print_topics(model, count_vectorizer, n_top_words):
fig = plt.figure(figsize=(15,8))
words = count_vectorizer.get_feature_names()
for topic_idx, topic in enumerate(model.components_):
print("\nTopic #", topic_idx, ":")
long_string = ','.join([words[i] for i in topic.argsort()[:-n_top_words - 1:-1]])
print(long_string)
topic_wordcloud(topic_idx, fig, long_string)
# show plots
fig.tight_layout()
fig.show()
def topic_wordcloud(topic_idx, fig, long_string):
ax = fig.add_subplot(2, 3, topic_idx + 1)
wordcloud = WordCloud(font_path=font_path, background_color="white", max_words=1000, contour_width=3, contour_color='steelblue')
wordcloud.generate(long_string)
ax.imshow(wordcloud)
ax.set_title('Topic '+str(topic_idx))
number_words = 500
print_topics(best_lda_model, count_vectorizer, number_words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment