Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Machine Learning Basic and Python

Yohei Munesada
September 12, 2017

Machine Learning Basic and Python

This slide describes Linear Regression Algorithm and how to implement it by Python.
Presented by http://www.yoheim.net

Yohei Munesada

September 12, 2017
Tweet

More Decks by Yohei Munesada

Other Decks in Technology

Transcript

  1.  About me w फఆ༸ฏʢΉͶͩ͞Α͏΁͍ʣ w Blog -> http://www.yoheim.net w

    Twitter -> @yoheiMune w ిࢠॻ੶αʔϏεͷاը։ൃ w ϓϥϯχϯάɺϑϩϯταʔόʔ։ൃɺσΟϨΫγϣϯɺ
 ෼ੳɺͳͲ
  2.  ୯ޠҰཡ ճؼ 3FHSFTTJPO ɺ෼ྨ $MBTTJpDBUJPO ɺ෼ྨث $MBTTJpFS ɺ ڭࢣ͋Γ

    4VQFSWJTFE ɺڭࢣͳ͠ 6OTVQFSWJTFE ɺ ઢܗճؼ -JOFBS3FHSFTTJPO ɺԾઆؔ਺ )ZQPUIFTJT ɺ ίετؔ਺ $PTU'VODUJPO ɺ໨తؔ਺ 0CKFDUJWF'VODUJPO ɺೋ৐ޡ ࠩ 4RVBSF&SSPS ɺฏۉೋ৐ޡࠩ .FBO4RVBSF&SSPS ɺ ޯ഑߱Լ๏ (SBEJFOU%FTDFOU ɺςετσʔλɺτϨʔχϯάσʔλɺ ֶशσʔλɺಛ௃ 'FBUVSF ɺଟ߲ࣜ 1PMZOPNJBM ɺਖ਼نԽ /PSNBMJ[BUJPO ɺΞϯμʔϑΟοτ 6OEFSpU ɺ)JHI#JBTɺ ΦʔόʔϑΟοτ 0WFSpU ɺߴ෼ࢄ )JHI7BSJBODF
  3.  $ python3 --version Python 3.5.2 $ pip3 —-version pip

    8.1.1 from /Library/Frameworks/Python.framework/ Versions/3.5/lib/python3.5/site-packages (python 3.5) Python3ܥΛΠϯετʔϧ͍ͯͩ͘͠͞ɻ ૝ఆ͍ͯ͠Δडߨऀ IUUQTXXXQZUIPOPSH Πϯετʔϧ͸ͪ͜Β͔Β →
  4.  1.2. ճؼͱ෼ྨ ػցֶशͷϞσϧ͸ɺճؼ 3FHSFTTJPO ͱ෼ྨ $MBTTJpDBUJPO ʹେผ͞Ε·͢ɻ ճؼ(Regression) ෼ྨ(Classification)

    ೖྗ͞Εͨσʔλ͔Β਺஋Λ༧ଌ͢ΔϞσϧɻ ྫɿϢʔβʔͷߪೖֹ༧ଌɺϢʔβʔͷεϚϗར༻࣌ؒ༧ଌ ೖྗ͞Εͨσʔλ͔Β෼ྨΛ༧ଌ͢ΔϞσϧɻ෼ྨث $MBTTJpFS ͱ΋ݺ͹ΕΔɻ ྫɿϢʔβʔ͕ߪೖ͢Δ͔൱͔ɺը૾ʹೣؚ͕·ΕΔ͔൱͔ɺखॻ͖਺஋ͷ஋͸Կ͔ʁ ༻ޠɿճؼ 3FHSFTTJPO ɺ෼ྨ $MBTTJpDBUJPO ɺ෼ྨث $MBTTJpFS
  5.  1.3. ڭࢣ͋Γͱڭࢣͳ͠ ػցֶशͷϞσϧ͸ɺڭࢣ͋Γ 4VQFSWJTFE ͱڭࢣͳ͠ 6OTVQFSWJTFE ʹେผ͞Ε·͢ɻ ڭࢣ͋Γ(Supervised) ڭࢣͳ͠(Unsupervised)

    ࣄલʹ༩͑ΒΕͨσʔλ τϨʔχϯάσʔλ Λ࢖ֶͬͯशΛߦ͍ɺͦΕΛ΋ͱʹ༧ଌ͢Δɻ ྫɿઢܗճؼɺϩδεςΟοΫճؼɺ47.ɺχϡʔϥϧωοτɺܾఆ໦ɺFUD ࣄલσʔλͳ͠ʹɺ༩͑ΒΕͨະ஌ͳσʔλ͔ΒԿΒ͔ͷຊ࣭తͳߏ଄Λಋ͖ग़͢ɻ ྫɿΫϥελϦϯάɺओ੒෼෼ੳɺFUD ༻ޠɿڭࢣ͋Γ 4VQFSWJTFE ɺڭࢣͳ͠ 6OTVQFSWJTFE
  6.  2.6. Ϟσϧͷվળ Ϟσϧվળʹ͸༷ʑͳख๏͕ଘࡏ͠·͢ɻ 㾎 τϨʔχϯάσʔλΛ૿΍͢ 㾎 ಛ௃Λ૿΍͢ 㾎 ಛ௃ΛݮΒ͢

    㾎 ଟ߲߲ࣜ໨Λ૿΍͢ 㾎 ৽͘͠ಛ௃Λ࡞੒͢Δ 㾎 ਖ਼ଇԽ߲ͷӨڹ౓ʢЕʣΛ૿΍͢ 㾎 ਖ਼ଇԽ߲ͷӨڹ౓ʢЕʣΛݮΒ͢ 㾎 σʔλͷਖ਼نԽ ༻ޠɿಛ௃ 'FBUVSF ɺଟ߲ࣜ 1PMZOPNJBM ɺਖ਼نԽ /PSNBMJ[BUJPO
  7.  2.6. Ϟσϧͷվળ Ϟσϧվળʹ͸༷ʑͳख๏͕ଘࡏ͠·͢ɻ 㾎 τϨʔχϯάσʔλΛ૿΍͢ 㾎 ಛ௃Λ૿΍͢ 㾎 ಛ௃ΛݮΒ͢

    㾎 ଟ߲߲ࣜ໨Λ૿΍͢ʢࠓճ͸͜Εʣ 㾎 ৽͘͠ಛ௃Λ࡞੒͢Δ 㾎 ਖ਼ଇԽ߲ͷӨڹ౓ʢЕʣΛ૿΍͢ 㾎 ਖ਼ଇԽ߲ͷӨڹ౓ʢЕʣΛݮΒ͢ 㾎 σʔλͷਖ਼نԽ
  8.  ճؼ 3FHSFTTJPO ɺ෼ྨ $MBTTJpDBUJPO ɺ෼ྨث $MBTTJpFS ɺ ڭࢣ͋Γ 4VQFSWJTFE

    ɺڭࢣͳ͠ 6OTVQFSWJTFE ɺ ઢܗճؼ -JOFBS3FHSFTTJPO ɺԾઆؔ਺ )ZQPUIFTJT ɺ ίετؔ਺ $PTU'VODUJPO ɺ໨తؔ਺ 0CKFDUJWF'VODUJPO ɺೋ৐ޡ ࠩ 4RVBSF&SSPS ɺฏۉೋ৐ޡࠩ .FBO4RVBSF&SSPS ɺ ޯ഑߱Լ๏ (SBEJFOU%FTDFOU ɺςετσʔλɺτϨʔχϯάσʔλɺ ֶशσʔλɺಛ௃ 'FBUVSF ɺଟ߲ࣜ 1PMZOPNJBM ɺਖ਼نԽ /PSNBMJ[BUJPO ɺΞϯμʔϑΟοτ 6OEFSpU ɺ)JHI#JBTɺ ΦʔόʔϑΟοτ 0WFSpU ɺߴ෼ࢄ )JHI7BSJBODF ୯ޠҰཡ
  9.  ࠓճֶ͹ͳ͔ͬͨ͜ͱ = ࣍ʹֶΜͰ΄͍͜͠ͱ ෼ྨ໰୊ͳͲଞͷΞϧΰϦζϜ ઢܗ୅਺Λ༻͍࣮ͨ૷ํ๏ 㾎 ϩδεςΟοΫճؼ47.χϡʔϥϧωοτϫʔΫϨίϝϯυFUD def compute_cost(x,

    y, Theta, lambda_=0): m = x.shape[0] hypo = np.dot(x, Theta) cost = np.sum((hypo - y) ** 2) + lambda_ * np.sum(Theta**2) return cost / 2 / m