SlideShare a Scribd company logo
1 of 61
やる夫で学ぶ SVM with R 発表者: y_benjo
自己紹介
[object Object]
[object Object]
[object Object],[object Object],[object Object]
イントロダクション 08年春
さて、機械学習の研究室に 入ったはいいけど 機械学習がわからないお…
というかここって一体 何をするところなんだお? 学習? AI ?人口知能?長門? かっこよさげな名前だけで研究 室を選んだのが間違いだったお ……
機械学習とはパターン認識 の一分野。 簡潔な言い方をすると、 ここは、どのようにデータ を分類するかという事に取 り組んでいる研究室。
急に変なのが出てきた! あんた誰だお?
私は長門有希。 研究室の M2 にして 今回の案内役。
一見無秩序に思える大量の データからいかに関係性を 見出すか、その為にどのよ うな手法が有効か。その手 法を考えるのが機械学習。
とりわけこの研究室では SVM について熱心に取り 組んでいる。 あなたの卒論・修論も、 おそらく SVM に関する内 容になるだろう
SVM って何だお? やる夫の知識は 2 年生の 「統計 2 」で止まってる んだお…
SVM は Support Vector  Machine と呼ばれる手法。 長くなるので次のスライド に
SVMとは
SVM とは Support Vector  Machine の略称です。 データ群を 2 クラスに分類する超平 面を引くことによってデータを分類 してしまおう という手法です。 具体例を挙げてみましょう。
例えば、このような点の集合があっ た場合、超平面はこのように引かれ ます。 このような分離を、超平面は線形な ので、「 線形分離 」と言います。
次にこのような場合、超平面は直線 状にならず、曲線状になってしまい ます。 このような分離を「 非線形分離 」と 呼びます。
ここで、気をつけてほしいことが あります。 さきほどの例では、超平面は直線に なっていましたが、これはデータが 2 次元のベクトルだからです(デー タが 3 次元なら超平面は平面)。 通常、データは d 次元なので「 超平 面 」という名が付けられています。
非線形分離の場合、 SVM は カーネル トリック という手法を使わなければ なりません。 その詳細は後述するとして、今回は 線形分離が可能なデータ集合を考え、 それを分離する SVM について取り上 げます。
『超平面』を引くことにより データを線形分離します!
だっておwwwwwwww 『超平面』とかどこの中二 病だおwwwwwwww 線を一本引くだけならやる 夫にも楽勝だおwwwww wwwwwwwwww
 
そこまで言うならあなたに SVM を実装 してもらう
Hello,World ですら友達の をコピペしたのにコンパイ ルエラーが出まくって先生 も諦めたレベルだお!? いきなり何を言い出すんだ お!? やる夫はプログラミングな んて全くできないお!
大丈夫、実装する言語には R を使ってもらう。 R なら行列操作も容易。
それに今回は線形分離だけ を行う SVM を作ってくれ ればいい。 カーネルメソッドはまた次 の機会( Tsukuba.R#3 ) にでも。
いやいや次とかないから
とりあえず数式を出し て欲しいお。 それを見ないと何とも 言えないお…(数式を 見たからといって実装 は無理だろうけど…)
SVMの簡単な理論
ここからは数式の説明に入りま す。ちょっとだけギリシャ文字 が出てきますが、適当に聞き流 しながら雰囲気を掴んでくださ い。 興味ない人はスルーしてハート マン軍曹が出てくるスライドだ け見てくれればおk
SVM は先ほど述べたように、 2 つのクラスを分割する「超平 面」 と呼ばれるものを引くアル ゴリズムです。 ではそれを定式化してみましょ う。
さて、今データ点を 2 次元のベ クトル として考え、このように 分布しているとしましょう。
この時、これらのデータを「 訓 練集合 」と呼びます。そして同 時に「 教師信号 」というものも 考えます。
いいか、これからお前ら 屑を教育してやる!!! じっくりかわいがってや る!泣いたり笑ったり出 来なくしてやる! その日まではウジ虫だ! 地球上で最下等の生命体 だ !
訓練集合 に対して教師信号を つまり、 訓練集合の各 データがクラス 1 なら 1 、 クラス 2 ならー 1 を取る ! 糞単純な話だ!わかった か! 念のため言っておくが各 データは d 次元のベクト ルだ!
訓練集合と教師信号の組 み合わせを        とし、これを「 学習デー タ 」と呼ぶことにする! 何故「学習」かというと、 これらのデータを元に超 平面が計算 されるからだ。 だから、学習データが糞 ならそこから得られる超 平面はまるでそびえたつ 糞だ!ジジイのファック の方がまだ気合が入って る!
では赤い点をクラス 1 、青い点 をクラス 2 としましょう。
そして、このように分離する超 平面の存在を仮定します。 この時、超平面は( w,b )という形で表されます。
「 超平面が (w,b) で表される 」 というのは、超平面に一番近い データ集合において となります。ここで、新たな データ集合が与えられた場合は、 等号が等号付き不等号に変わり ます。
そして、 各訓練集合から超平面 までの距離 を γ とし、これを 幾 何マージン と呼ぶことにしま しょう。
この時、幾何マージン γ は で表されます。マージンは、 超 平面と各訓練集合との距離 を示 していますから、 マージンは大 きければ大きいほど良い という 事になります。
ここで、次のような最大化問題 を考えます。 Max:     -> Min: s.t (∵教師信号の定義より)
寝てる奴は起きろ!これ から要点だけまとめてや る! 1)SVM は超平面=境界 を引く! 2) その時、境界からの距 離をマージンと呼ぶ! 3) マージンはできるだけ 大きくする!
よしお前ら、お前らの仕 事はこの マージン最大化 問題を解く事 だ! それまでじっくり可愛 がってやる!泣いたり 笑ったりできなくしてや る! わかったか、ウジ虫!
……… ハッ!
無理だお!!!! 数理計画の授業で死に 掛けたやる夫には無理 すぎて死ぬお!!!
問題無い。そこで R を使う。 他のプログラミング言語で あればニュートン法や最急 降下法を使うところだが、 R なら二次計画のパッケー ジが用意されている。
ならきっとどうにかなるお…… 色々ぐぐりながらやってみるお
とりあえずこの式をラグラン ジュの未定乗数法を使って凸二 次計画問題に変形して… ここ説明すんのだるいので省く お。
二次計画を解くための R のパッ ケージは quadprog 、関数は solve.QP() らしいお…えーっと … 使い方は…っと…
Solve a Quadratic Programming Problem Description: This routine implements the dual method of Goldfarb and Idnani (1982, 1983) for solving quadratic programming problems of the form min(-d^T b + 1/2 b^T D b) with the constraints A^T b >= b_0. Usage: solve.QP(Dmat, dvec, Amat, bvec, meq=0, factorized=FALSE) … 日本語でおk
と、とにかく…引数に合うよう に式を変形させて…条件式はそ のまま使えそうだから使って…
を、行列表現に書き換えれば 後半部分はそれぞれ、 x_i ・ x_j を要素に持つ行列Xと、 y_iy_j を要素に持つ行列Yに書き換え て… X*Y ってやれば要素が な行列が出来るハズだお…
やったらエラー吐くお! つうか半正定値行列になら ないお!!!
… kernlab パッケージの ipop も使えなかったし…
……
 
 
 

More Related Content

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

SVM&R with Yaruo!!