読書履歴から本のクラスタリングと特徴量の抽出を行います。
anaconda3.4.3-0
beautifulsoup4
tqdm
numpy
pandas
requests
matplotlib
joblib
lxml
gensim
$ ruby scrapter.rb
実行すると ./data/raw
配下に読書履歴をダウンロードします. スクレイピングはサーバーに負荷をかけない程度に行ってください。
実行される前に ./data/raw
直下にデータが保存されている必要があります。
from features import load_feature, compile_corpus_and_dictionary
data = load_feature(root_path="./data/raw/", target="title")
corpus, dictionary = compile_corpus_and_dictionary(data, no_below=5, save_to="checkpoints/dictionary.txt")
from lda import LDATrainer
lda_trainer = LDATrainer(output_dir="./checkpoints/")
lda_trainer.run(corpus, dictionary, topics=10) # 学習の実行
# 上位のトピックを保存
lda_trainer.show_topics(save_to_dir="./checkpoints/")
from word_to_vec import W2VTrainer
w2v_trainer = W2VTrainer(output_dir="./checkpoints/")
w2v_trainer.run(data)
topic 1
[('阪急電車(幻冬舎文庫)', 0.0013286450514788421),
('和菓子のアン(光文社文庫)', 0.0010029719922129846),
('永遠の0(講談社文庫)', 0.00095220966510543164),
('氷菓(角川文庫)', 0.000931927887614856),
('火花', 0.00088232395541623144),
('レインツリーの国(新潮文庫)', 0.00087065130728654241),
('ビブリア古書堂の事件手帖3~栞子さんと消え…', 0.00083625459565052221),
('陽だまりの彼女(新潮文庫)', 0.00078834353368666273),
('夜は短し歩けよ乙女(角川文庫)', 0.00076325430885853943),
('ぼくは明日、昨日のきみとデートする(宝島社…', 0.00076090024369739853)]
topic2
[('永遠の0(講談社文庫)', 0.0012030737598141335),
('阪急電車(幻冬舎文庫)', 0.0011685757490659541),
('イニシエーション・ラブ(文春文庫)', 0.0011032171029623371),
('舟を編む', 0.00093492775265262469),
('西の魔女が死んだ(新潮文庫)', 0.00085344844568903389),
('夜のピクニック(新潮文庫)', 0.00084074342930131642),
('図書館戦争図書館戦争シリーズ(1)(角…', 0.00079957001036084336),
('カラフル(文春文庫)', 0.00078677125722370774),
('死神の精度(文春文庫)', 0.00077641049565474061),
('ぼくは明日、昨日のきみとデートする(宝島社…', 0.00076590742659798081)]
近い本
[('三四郎(新潮文庫)', 0.8102374076843262),
('こころ(新潮文庫)', 0.7891632914543152),
('門(新潮文庫)', 0.7769464254379272),
('草枕(新潮文庫)', 0.7562223672866821),
('虞美人草(新潮文庫)', 0.7479068636894226),
('阿部一族・舞姫(新潮文庫)', 0.7449460625648499),
('坊っちゃん(新潮文庫)', 0.7428607940673828),
('それから(新潮文庫)', 0.7405833005905151),
('行人(新潮文庫)', 0.7404835224151611),
('道草(新潮文庫)', 0.7297923564910889)]
遠い本
[('死神姫の再婚-五つの絆の幕間劇-(ビーズ…', 0.13127756118774414),
('絶園のテンペスト2(ガンガンコミックス)', 0.1260046362876892),
('死神姫の再婚-始まりの乙女と終わりの教師-…', 0.1172419935464859),
('信長協奏曲1(ゲッサン少年サンデーコミッ…', 0.09469656646251678),
('レベルE(上)(集英社文庫―コミック版)', 0.09304021298885345),
('絶園のテンペスト(5)(ガンガンコミックス)', 0.09189711511135101),
('信長協奏曲7(ゲッサン少年サンデーコミッ…', 0.09187307208776474),
('信長協奏曲2(少年サンデーコミックス)', 0.08920496702194214),
('天使1/2方程式1(花とゆめCOMICS)', 0.08579257875680923),
('闇の皇太子偽悪の革命家(ビーズログ文庫)', 0.08444569259881973)]