Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TokyoR#54 コサイン距離を用いたクラスタリング
Search
bob3bob3
January 12, 2022
Programming
480
0
Share
TokyoR#54 コサイン距離を用いたクラスタリング
コサイン距離を用いたクラスタリング。
2016年6月。
bob3bob3
January 12, 2022
More Decks by bob3bob3
See All by bob3bob3
RとLLMで自然言語処理
bob3bob3
3
840
RでPSM分析
bob3bob3
1
420
Rでコンジョイント分析 2024年版
bob3bob3
0
2.3k
『改訂新版前処理大全』の話と Apache Parquet の話 #TokyoR
bob3bob3
0
1.4k
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
640
『データ可視化学入門』をPythonからRに翻訳した話(増強版)
bob3bob3
0
570
『データ可視化学入門』を PythonからRに翻訳した話
bob3bob3
1
640
qeMLパッケージの紹介
bob3bob3
0
2.4k
「国と音楽」 ~spotifyrを用いて~ #muana
bob3bob3
2
640
Other Decks in Programming
See All in Programming
AIと共にエンジニアとPMの “二刀流”を実現する
naruogram
0
110
Tamach-sre-3_ANDPAD-shimaison93
mane12yurks38
0
210
Coding at the Speed of Thought: The New Era of Symfony Docker
dunglas
0
3.5k
Laravel Nightwatchの裏側 - Laravel公式Observabilityツールを支える設計と実装
avosalmon
1
270
Symfonyの特性(設計思想)を手軽に活かす特性(trait)
ickx
0
110
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
250
存在論的プログラミング: 時間と存在を記述する
koriym
5
590
Feature Toggle は捨てやすく使おう
gennei
0
390
Everything Claude Code OSS詳細 — 5層構造の中身と導入方法
targe
0
160
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
350
[PHPerKaigi 2026]PHPerKaigi2025の企画CodeGolfが最高すぎて社内で内製して半年運営して得た内製と運営の知見
ikezoemakoto
0
310
Java 21/25 Virtual Threads 소개
debop
0
310
Featured
See All Featured
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
160
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
How STYLIGHT went responsive
nonsquared
100
6k
Optimizing for Happiness
mojombo
378
71k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
260
The Curious Case for Waylosing
cassininazir
0
280
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
500
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Building an army of robots
kneath
306
46k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.2k
Transcript
コサイン類似度を用いた クラスタリング @bob3bob3 Tokyo.R #54 2016/06/19
お伝えしたいこと • いわゆるビッグデータによくあるスパース な行列のクラスタリングにはコサイン類似 度を使うといい感じだよ。 • コサイン類似度を用いたクラスタリングは skmeansパッケージで実行できるよ。 • このLTの内容は『マーケティング・サイエ
ンスのトップランナーたち』の第2章「商 品市場を細分化するビッグデータ適合型ク ラスター分析の活用」がネタ元だよ。
同じような購買傾向の消費者を グループ化したい ケース1 ビール ワイン 日本酒 焼酎 ウイスキー Aさん 1
1 Bさん 1 ケース2 ビール ワイン 日本酒 焼酎 ウイスキー Cさん 1 1 1 Dさん 1 1 1 1 この二人は別々のグループにしたい この二人は同じグループにしたい
K-means法で使用される ユークリッド距離だと ケース1 ビール ワイン 日本酒 焼酎 ウイスキー Aさん 1
1 Bさん 1 ケース1 ビール ワイン 日本酒 焼酎 ウイスキー Aさん 1 1 1 Bさん 1 1 1 1 ユークリッド距離:1.732 ユークリッド距離:1.732
1-コサイン類似度だと ケース1 ビール ワイン 日本酒 焼酎 ウイスキー Aさん 1 1
Bさん 1 ケース1 ビール ワイン 日本酒 焼酎 ウイスキー Aさん 1 1 1 Bさん 1 1 1 1 1−コサイン類似度:1.000 1−コサイン類似度:0.423
skmeansパッケージを使ってみる # 関連規則のパッケージに入っているサンプルデータを使う library(arules) # transactions形式のサンプルデータ data(Groceries) # スパースなデータを扱いやすくするパッケージ。圧倒的に処理が早い。 library(slam)
# transactions形式からmatrix形式に Groceries.mat <- as(Groceries,"matrix") # 真偽値を0/1に変換 Groceries.mat <- ifelse(Groceries.mat==TRUE,1,0) # matrix形式からstm形式へ Groceries.stm <- as.simple_triplet_matrix(Groceries.mat)
skmeansパッケージを使ってみる # コサイン距離を使ったkmeans library(skmeans) set.seed(1234) #再現性のための乱数種設定 res <- skmeans(Groceries.stm, k=05)
table(res$cluster) #各クラスタのサイズ aggregate(Groceries.mat, by=list(res$cluster), mean)
Enjoy!