-
Notifications
You must be signed in to change notification settings - Fork 10
Add: 「k 近傍法でレモンサワーを探せ」 by @ゆーか(FREE) #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new article titled "k 近傍法でレモンサワーを探せ" (Finding Lemon Sour Using k-NN) by ゆーか (Yuuka) to the free section. The article explores using machine learning (k-nearest neighbors algorithm) to solve the playful question of "what drinks are similar to lemon sour?" by comparing implementations in Python and Ruby.
Key changes:
- Added a comprehensive 568-line article covering k-NN implementation comparison between Python and Ruby
- Updated the configuration to include the new article entry
- Updated the table of contents to reflect the new article addition
Reviewed Changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
free/53-yuuka.md | New article implementing k-NN algorithm comparison between Python and Ruby for drink similarity search |
nest/nest.js | Added configuration entry for the new article and fixed formatting issues with trailing commas |
common/toc.md | Updated table of contents to include the new article entry |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
## 自由 | ||
7. [ChatGPTの効果的な使い方](#01-sample) — Tanaka | ||
8. [Samlpe Title](#02-sample) — Taro | ||
7. [k 近傍法でレモンサワーを探せ"](#53-yuuka) — ゆーか |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an extra quotation mark at the end of the article title. It should be k 近傍法でレモンサワーを探せ
without the trailing quote mark.
7. [k 近傍法でレモンサワーを探せ"](#53-yuuka) — ゆーか | |
7. [k 近傍法でレモンサワーを探せ](#53-yuuka) — ゆーか |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
めっっっっちゃ面白かったです!!ゆーかさんらしい文章をありがとうございました。
[❓ASK]と[🍠IMO]の箇所だけご確認いただき、問題なければその旨ご返信ください。🙏
|
||
## はじめに | ||
|
||
**「レモンサワーに似た飲み物は何だろう?」** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
入りがもう好き。
居酒屋でレモンサワーを頼んで飲むと...ん?レモンサワー?いや、何か別の飲み物に似ているような...。 | ||
居酒屋飲み放題あるある、「これお酒入ってる?」「レモンの味...する?」...というありふれた日常から生まれたこの疑問を、機械学習を使って解決してみました。 | ||
|
||
とはいえ私の機械学習の知識はほぼゼロのレベルです。毎週実施している輪読会で **k 近傍法**を知り、レコメンド機能ってこういうアルゴリズムからできるんだ!と興味を持ち今回の実装に挑戦してみました。エンジニアが集まるとつい、「どれ頼んだらレモンサワーの味するドリンクくるのかな?」と**デバッグ感覚で飲み比べを始めてしまう。**そんなくだらないからこそ楽しい記憶をふと思い出し、k 近傍法で検索してみることにしました。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
デバッグ感覚で飲み比べを始めてしまう。
www
|
||
### ゴール | ||
|
||
Ruby 学習者の視点から**「くだらない疑問を真面目に解決する」**姿勢で筆者のレベルで、下記を比較・考察します。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最高!
|
||
機械学習というと Python のイメージが強いですが、Ruby にも **Annoy ライブラリ**などが存在することを知りました。 | ||
しかし Python と比較すると Ruby は機械学習に関する情報が少ない印象もあり、実際の性能や開発体験はどうなのか疑問でした。 | ||
また、単純な技術比較ではなく、この技術を使ってどのように課題を解決できるのかという観点も含めて検証したいと考えました。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
素敵
|
||
**【Python:ライブラリの豊富さが開発を加速】** | ||
|
||
**scikit-learn** の使用でドキュメントも破りやすく、わずか数行で高性能な類似度検索を実現できました。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[❓ASK]
破りやすく
って言葉があるのでしょうか。用語なのか間違いなのか語彙力がなく判断つかなかったので念の為指摘させてください。
**なぜ Python が高速になったのか** | ||
|
||
- ベクトル化のみ Ruby が有利だが、小規模データでは 22.1 倍高速であったのに対して 6.9 倍まで落ちており、それ以外の処理項目はは Python が圧倒的 | ||
- scikit-learn や NumPy による 並列化・メモリ最適化・C 実装 の効果が大きい |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ぎょえーーーーおもろい。やっぱNumPyつおいんだ
|
||
## 4. 結果「レモンサワーに似た飲み物は何だろう?」 | ||
|
||
さて、ここまで実装方法やその速度についてみてきました。いよいよ最後にレモンサワーに似た飲み物についてみていきます。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そうでした、忘れてました
### レモンサワーに似た飲み物の検索結果 | ||
|
||
結論としては**「レモンサワーに似た飲み物はハイボールレモン」**となりました。 | ||
2 位のレモンモヒート(Python: 0.4814、Ruby: 0.5164)もレモン系の飲み物ですが、炭酸がない点でレモンサワーとの類似度が下がっていると考えられます。さらに 3 位のレモンジュース(Python: 0.3485、Ruby: 0.3333)はアルコールが含まれていないため、さらに類似度が低くなったと考えました。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すごい、ちゃんと判別されてる
|
||
先ほど「TF-IDF と単語頻度ベクトル」で補足説明した箇所を実際に実行してみました。 | ||
レモンサワーの結果と異なるポイントは、**「ピーチ果汁」と「ピーチリキュール」の類似性を判断できるか**です。 | ||
**`peach_oolong` の結果に注目してください。**Ruby では自前実装のため少し精度を落とし、単語頻度ベクトルでベクトル化しているため同じピーチ系のドリンクでも「ピーチ果汁」を使用する `peach_highball, peach_mojito, peach_juice` に対して、「ピーチリキュール」を使用する `peach_oolong` は類似性があると判断できず**類似度は 0.0** という結果になりました。一方、Python ではライブラリを使用し類似性があると判断できるため**類似度が 0.1606** と計算されていることがわかります。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ほんとだすごい
|
||
特に印象的だったのは、同じアルゴリズムでもベクトル化の手法によって結果が変わることです。Python では TF-IDF で文字レベルの N-gram を採用することで、`peach_juice`と`peach_liqueur`のような微妙な違いも捉えられるようになり、想定通りの結果が出た時にはとても感動しました。 | ||
|
||
改めて、薬剤師からエンジニアへ転職して楽しいなと思うのは「正確性より、まず動かしてみる」という考え方がメインになったことかもしれません。今回 k 近傍法に関して手を動かしてみるきっかけになったのは、一緒に学ぶ仲間がいたからこそでした。興味を持った内容を議論できる相手がいたから実装に挑戦し、完璧な実装ではありませんが、実際に手を動かして試行錯誤し比較することで多くの学びを得られました。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
めちゃくちゃ素敵な締めをありがとうございます!!
執筆テーマ(NEST / HUB / フリー)
フリー
記事の概要(2〜3 行)
飲み会で浮かんだ「レモンサワーに似た飲み物ってんだろう」というくだらない疑問を、k近傍法を用いて真面目に解決を目指してみました。