Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
TokyoR#54 コサイン距離を用いたクラスタリング
Search
bob3bob3
January 12, 2022
Programming
520
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TokyoR#54 コサイン距離を用いたクラスタリング
コサイン距離を用いたクラスタリング。
2016年6月。
bob3bob3
January 12, 2022
More Decks by bob3bob3
See All by bob3bob3
RとLLMで自然言語処理
bob3bob3
3
1.1k
RでPSM分析
bob3bob3
1
560
Rでコンジョイント分析 2024年版
bob3bob3
0
2.9k
『改訂新版前処理大全』の話と Apache Parquet の話 #TokyoR
bob3bob3
0
1.5k
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
670
『データ可視化学入門』をPythonからRに翻訳した話(増強版)
bob3bob3
0
630
『データ可視化学入門』を PythonからRに翻訳した話
bob3bob3
1
690
qeMLパッケージの紹介
bob3bob3
0
3k
「国と音楽」 ~spotifyrを用いて~ #muana
bob3bob3
2
700
Other Decks in Programming
See All in Programming
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
970
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
610
Jetpack Compose Mechanisms
skydoves
3
820
JIS keyboard support in Omarchy
lef237
0
130
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
780
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
510
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
AmebaブログはKMPから卒業します
kmars0605
0
200
Featured
See All Featured
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
630
HDC tutorial
michielstock
2
960
sira's awesome portfolio website redesign presentation
elsirapls
0
460
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
570
Exploring anti-patterns in Rails
aemeredith
4
540
A designer walks into a library…
pauljervisheath
211
25k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
440
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
260
Abbi's Birthday
coloredviolet
4
10k
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!