SlideShare a Scribd company logo
1 of 113
Download to read offline
機械学習
レポート ID *****ai0025273
機械学習
0) 前置き
1) 線形回帰モデル
2) 非線形回帰モデル
3) ロジスティックス回帰モデル
4) 主成分分析(PCA)
5) k近傍法(kNN)、k-平均法(k-means)アルゴリズム
6)サポートベクターマシーン(SVM)
機械学習モデリングプロセス
1.問題設定
どのような課題を機械学習で解決させるか?(もっとも重要)
2.データ選定
どのようなデータを使うか(課題解決に合ったデータであるか。バイアス、分布が適切か)
3.データの前処理
モデルの選定、調整は全体の
2割程度。データの前処理も重要
.欠損値処理
4.機械学習モデル選定
種類:線形回帰、k-means,ロジスティックス回帰、PCA、SVM(ハードル)、knn
5.モデルの学習
6.モデルの評価
機械学習の種類
教師あり学習
予測タスク: 線形回帰・非線形回帰(最小二乗法、尤度最大化)
分類タスク: ロジスティックス回帰(尤度最大化)
最近傍、k-近傍
SVM(マージン最大化)
モデル評価: ホールドアウト法、交差検証法
教師なし学習
クラスタリングタスク:k-means
次元削減:主成分分析(分散最大化)
ルールベースモデルと機械学習モデル
ルールベースモデル
ルール、重みを人が調整する
機械学習モデル
ルール、重みを機械が調整する(アルゴリズムで調整する)
数学が重要
線形回帰モデル
線形とは・・・・ざっくり比例
y = Ax +B
z = Ax + By +C
※ n次元空間における超平面の方程式
y = Ax + b
行列を使用して上記で表せるもの
線形回帰モデル
回帰問題とは
ある入力(離散値or連続値)から出力を予測する問題
直線で予測:線形回帰
曲線で予測:非線形回帰
回帰で扱うデータ
入力(各要素:説明変数、特徴量):m次元のベクトル(m=1ではスカラ)
出力(目的変数):スカラー値
m個実数の集合
線形回帰モデル
線形回帰モデルとは
・回帰問題を解くための機械学習モデルの1つ
・教師あり学習(教師データから学習)
・入力とm次元パラメータの線形結合を出力するモデル
慣例として予測値にハットをつけ、正解データと区別する
線形回帰モデル
線形結合(入力とパラメータの内積)
線形回帰モデル
モデルのパラメータ
モデルに含まれる推定すべき未知のパラメータ
特徴量が予測値に対してどのように影響を与えるかを決定する重みの集合
正の(負の)重み:その特徴量の値を増加させると、予測の値が増加(減少)
重みが大きい(0):その特徴量は予測に大きな影響力を持つ(全く影響しない)
切片:y軸との交点を表す
線形回帰モデル
線形単回帰:説明変数が1次元の場合(m=1):直線
線形重回帰:説明変数が多次元の場合(m>1):曲線
線形回帰モデル
線形回帰モデル
線形回帰モデルパラメータwは最小二乗法で推定
・平均二乗誤差(残差平方和)Mean Squer Error
小さいほど直線とデータの距離が近い
パラメータのみに依存する関数
・最小二乗法
学習データの平均二乗誤差を最小とするパラメータwを探索
学習データの平均二乗誤差の最小化は勾配(微分)が0になる点を求める
線形回帰モデル
求めたいものは、ω これを解くと
これが、最小二乗法の解と一致する。
線形回帰モデル
MSEを最小(min)とするw
行列演算については
  The Matrix Cookbook 

が参考になる
線形回帰モデル
線形回帰モデルパラメータwは最小二乗法で推定
・平均二乗誤差(残差平方和)Mean Squer Error
小さいほど直線とデータの距離が近い
射影行列
予測したい新たな入力点
線形回帰モデル(実装)
ボストンの住宅価格データセット(scikit-learn提供)
住宅平均部屋数RMから価格を予測
データセット読み込み
RMを説明変数Xとして 
PRICE を目的変数として
モデルの重み
グラフ表示
予測直線
モデルの学習
学習データ整備
切片追加
線形回帰モデル(実装)重回帰分析
ボストンの住宅価格データセット :住宅平均部屋数RM(部屋数の平均),CRIM(人口 1
人当たりの犯罪の発生数)から価格を予測
グラフ表示
モデルの重み
CRIM 重み小さい
線形回帰モデル(実装)重回帰分析
学習結果をグラフ表示
Plotly インポート
回帰結果
回帰結果
非線形回帰モデル
非線形回帰モデル
線形回帰モデル
非線形回帰モデル
  重みに対しては線形(線形モデルによる非線形回帰)
Φ(x4)
非線形回帰モデル
非線形回帰モデル
基底関数Φ(x)に多項式関数の場合
wについて線形
ガウス型基底関数
非線形回帰モデル(多項式実装)
x,x^2,x^3 3次の場合
データ数10
10次の場合
過学習が発生
学習部
非線形回帰モデル
山の重ね合わせ
4次以上はほぼ
変わらない
非線形回帰モデル
非線形回帰モデル
線形回帰と同じ形状
非線形回帰モデル
非線形回帰モデル
よくない
よくない
特徴選択
 ドメイン知識
非線形回帰モデル
不要な基底関数を削除
基底の数、位置やバンド幅によりモデルの煩雑さが変化
    ->赤池情報量基準(AIC) モデルの良さを評価する指標
解きたい問題に対して多くの基底関数を用意してしまうと過学習の問題がおこる
適切な基底関数を用意(CVなどで選択)
非線形回帰モデル
正則化法
モデルの煩雑さに伴って、その値が大きくなる正則化項(罰則項)を課した関数
かなり大きくなる
非線形回帰モデル
解きたいのは、minMSE s.t. R(w) ≦ r (この条件を満たしつつ)
↓
最適化:KKT条件より
min MSE + λ・R(w) ← 追加項で不等式条件がなくなる
w0
w1
MSE
min MSE
w0 = 0
非線形回帰モデル
過学習が防げる
非線形回帰モデル
数の暴力(データ数があればほぼ見える
検証法
検証法
検証法
検証法
検証法
適切 汎化性能
悪い
過学習
errorが減らないモデルが足り
ない
検証法
・ホールドアウト データを学習用、テスト用で分割
分割されたデータ内に外れ値があった場合のリスクがある
・クロスバリデーション
検証法
クロスバリデーション 評価
検証法
クロスバリデーション 評価 一番CVが良いものを採用
ハイパーパラメータの選定法
ロジスティックス回帰モデル
ロジスティックス回帰モデル
ロジスティックス回帰モデル
ロジスティックス回帰モデル
シグモイド関数の性質
・シグモイド関数の微分は、シグモイド関数自身で表現することが可能
→計算が容易、バックプロパゲーションが行いやすい
ロジスティックス回帰モデル
ロジスティックス回帰モデル
判断(閾値を保留にできる)
ロジスティックス回帰モデル
世の中には様々な確率分布がある
・正規分布、t分布、ガンマ分布、一様分布、ディリクレ分布
・ロジスティックス回帰モデルでは、ベルヌーイ分布を利用する
ベルヌーイ分布
・数学において確率pで1,確率1-p で0をとる、離散確率分布(例:コイン投げ)
・「生成されるデータ」は分布のパラメータによって異なる
ロジスティックス回帰モデル
ベルヌーイ分布のパラメータ推定
・ある分布を考えたとき、そのパラメータ(既知)によって、
生成されるパラメータは変化する
・データからそのデータを生成したであろう、尤(もっと)もらしい分布
(パラメータ)を推定したい => 最尤推定
ロジスティックス回帰モデル
同時確率
・あるデータが得られたとき、それが同時に得られる確率
・確率変数は独立であることを仮定すると、それぞれの確率の掛け算となる
尤度関数とは
・データは固定し、パラメータを変化される
・尤度関数を最大化するようなパラメータを選ぶ方法を最尤推定という
ロジスティックス回帰モデル
ロジスティックス回帰モデル
ロジスティックス回帰モデル
ロジスティックス回帰モデル
尤度関数を最大とするパラメータを探す(推定)
○対数をとると微分の計算が簡単
■同時確率の積が和に変換可能
■指数が積の演算に変換可能
○対数尤度関数が最大になる点と尤度関数が最大になる点は同じ
■対数関数は単調増加(ある尤度の値がx1 < x2の時、必ずlog(x1) < log(x2)となる)
○「尤度関数にマイナスをかけたものを最小化」し、「最小
2乗法の最小化」と合わせる
分母が0にならないように、桁落
ちしないように
ロジスティックス回帰モデル
勾配降下法(Gradient descent) https://qiita.com/masatomix/items/d4e5fb3b52fa4c92366f
・反復学習によりパラメータを逐次的に更新するアプローチの一つ
・ηは学習率でハイパーパラメータ。モデルのパラメータの収束しやすさを調整
なぜ必要か?
・線形回帰モデル(最小二乗法)-> 解析的に誤差関数が0を求められた
・ロジスティックス回帰->対数尤度関数を微分して0になる値を求める
解析的に求めることが困難なため
ロジスティックス回帰モデル
微分の連鎖律(合成関数の微分)
ロジスティックス回帰モデル
nが大きいと計算が膨大
ロジスティックス回帰モデル
ロジスティックス回帰モデル
性能の指標 混同行列(confusion matrix)
ロジスティックス回帰モデル
混同行列による評価方法まとめ
https://analysis-navi.com/?p=550
F値(適合率・精度 P と再現率Rの調和平均)
P=
R=
ロジスティックス回帰モデル(実装)
ロジスティックス回帰モデル(実装)
ロジスティックス回帰モデル(実装)
主成分分析(PCA:principal component analysis)
多変数量データの持つ構造をより少数個の指標に圧縮=>次元削減
・変数の個数を減らすことによる、情報の損失を小さくしたい
・少数変数を利用した分析や可視化(2,3次元の場合)が実現可能
主成分分析(PCA)
軸の再設定
主成分分析(PCA)
主成分分析(PCA)
主成分分析(PCA)
Ax = λx の形
→固有値
主成分分析(PCA)
主成分分析(PCA)実装
主成分分析(PCA)実装(1)
第1主成分
第2主成分
主成分分析(PCA)実装(1)
軸の回転
主成分分析(PCA)実装(2)
主成分分析(PCA)実装(2)
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
k近傍法(kNN)
・教師あり学習 分類問題
(AとBに分類されたデータがあり、新しいデータがどれに分類され
るかを求める)
k-平均法(k-means)
・教師なし学習 クラスタリング手法
(データがあるが、どう分類するかを決定する方法)
・与えられたデータをk個のクラスタの分類
  k:指定する スーパーパラメータ
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
k近傍法(kNN)
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
・kを変化させると結果も変わる
・kを大きくすると決定境界は滑らかになる
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
k-平均法(k-means)
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
k-平均法(k-means)アルゴリズム
1) 各クラスタ中心の初期値を設定する
2) 各データ点に対して、各クラスタ中心との距離を計算し、最も距
離が近いクラスタを割り当てる
3) 各クラスタの平均ベクトル(中心)を計算する
4) 収束するまで2, 3の処理を繰り返す
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
k近傍法(kNN)、k-平均法(k-means)アルゴリズム
サポートベクターマシン(SVM)
・教師あり学習 分類問題
・2クラス分類のための機械学習手法
・線形モデルの正負で2値分類
サポートベクターマシン(SVM)
マージンが最大となる線形判別関数を求める
マージン:線形判別関数ともっとも近いデータ点との距離
サポートベクターマシン(SVM)
目的関数の導出準備
サポートベクターマシン(SVM)
目的関数の導出準備
サポートベクターマシン(SVM)
主問題の目的関数と制約条件
上の最適化問題をラグランジュ未定乗数法で解くことを考える
サポートベクターマシン(SVM)
ラグランジュの未定乗数法
・制約条件付き最適化問題を解くための手法
サポートベクターマシン(SVM)
KKT条件
・制約付き最適化問題において最適解が満たす条件
サポートベクターマシン(SVM)
ラグランジュの未定乗数法
サポートベクターマシン(SVM)
双対問題
サポートベクターマシン(SVM)
主問題と双対問題
・主問題の最適解と双対問題の最適解は一対ー対応
サポートベクターマシン(SVM)
予測
・SVMの決定関数
サポートベクターマシン(SVM)
分離超平面を構成する学習データは、サポートベクターだけで
残りのデータは不要
サポートベクターマシン(SVM)
ソフトマージンSVM
・サンプルを線形分離できないとき
・誤差を許容し、誤差に対してペナルティを与える
サポートベクターマシン(SVM)
サポートベクターマシン(SVM)
ソフトマージンSVM
・線形分離できない場合でも対応
・パラメータCの大小で決定境界が変化
サポートベクターマシン(SVM)
非線形分離
・線形分離できないとき
→ 特徴空間に写像し、その空間で線形に分離する
サポートベクターマシン(SVM)
カーネルトリック
サポートベクターマシン(SVM)
非線形カーネルを用いた分離
・非線形な分離が可能
サポートベクターマシン(SVM) 実装 ①
サポートベクターマシン(SVM) 実装 ①
サポートベクターマシン(SVM) 実装 ①
マージンの最大化
サポートベクターマシン(SVM) 実装 ②
サポートベクターマシン(SVM) 実装 ②
サポートベクターマシン(SVM) 実装 ③
サポートベクターマシン(SVM) 実装 ③

More Related Content

Featured

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
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
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
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...
 

機械学習