分位点回帰 / quantile regression

5346146aca9add2e6c02b01bf4c0df2e?s=47 jeey
May 29, 2020

分位点回帰 / quantile regression

5346146aca9add2e6c02b01bf4c0df2e?s=128

jeey

May 29, 2020
Tweet

Transcript

  1. Q u a n t i l e R e

    g r e s s i o n Q u a n t i l e R e g r e s s i o n Q u a n t i l e R e g r e s s i o n Q u a n t i l e R e g r e s s i o n Q u a n t i l e R e g r e s s i o n Q u a n t i l e R e g r e s s i o n Q u a n t i l e R e g r e s s i o n ෼Ґ఺ ճؼ
  2. 1. ༧ଌͷ৴པੑͱ͸ 2. ༧ଌͷ৴པੑͷϞσϦϯά 3. ϐϯϘʔϧଛࣦؔ਺ 4. ଛࣦؔ਺ʹΑΔ෼Ґ఺ͷਪఆ 5. ར༻ՄೳͳϥΠϒϥϦ

  3. 1. ༧ଌͷ৴པੑͱ͸

  4. Ͳͬͪͷ༧ଌ΋ಉ͘͡Β͍৴པͰ͖Δ͔ͳʁ

  5. ෼ੳ՝୊ʹ͓͍ͯɺ͋Δ༧ଌͷ֬౓ΛҙࢥܾఆͷҰॿͱ͍ͨ͠৔ ߹͕͋Δ ·ͨɺ࣮ଌ஋ΑΓ΋্ৼΕɾԼৼΕͨ͠஋Λࢀߟʹҙࢥܾఆͨ͠ ΄͏͕ɺ҆શଆͷ൑அͱͳΔ৔߹͕͋Δ ༧ଌͷ৴པੑ

  6. ༧ଌͷ෯͕ ໰୊ͱͳΔ৔߹ ྫʣ౤ࢿ൑அ ࠷େརӹͱͳΔ༧ଌ఺͕ਪఆ͞Εͨͱͯ͠΋ɺͦ Ε͕ಉ࣌ʹ࠷௿རӹͱͳΔՄೳੑ΋͋Δ͘Β͍ෆ ֬ఆͳ༧ଌͰ͋Δ৔߹͸ɺͦΕΑΓ΋རӹ͸΍΍ ௿͍͕ݻ͍༧ଌ఺Ͱ౤ࢿ൑அΛߦ͍͍ͨɺͱ͍͏ Α͏ͳϦεΫධՁ΋ಉ࣌ʹߦ͍͍ͨ৔߹͕͋Δ ʢϘϥςΟϦςΟͷ༧ଌʣ ͜ΜͳઢΛҾ͍ͯɺϦεΫͱϦλʔϯͷόϥϯε

    Λͱͬͯҙࢥܾఆ͍ͨ͠
  7. ༧ଌͷ্ৼΕ͕ ໰୊ͱͳΔ৔߹ ྫʣ৯඼খചۀऀ Ұൠʹ95%Ҏ্ͷඇৗʹߴ͍αʔϏεϨϕϧΛ௥ ٻ͢Δʢͭ·Γɺࡏݿ੾Ε͸ඇৗʹكʣ ͜ͷ৔߹ɺଈ࣌ൢചͷࡏݿ͕ͳ͍ΑΓɺ༨৒ࡏݿ Λ๊͑Δ΄͏͕ྑ͍ͱ൑அ͞ΕΔ ্ৼΕͷઢΛҾ͍ͯɺ͜ͷ༧ଌͰҙࢥܾఆΛ͍ͨ͠

  8. ༧ଌͷԼৼΕ͕ ໰୊ͱͳΔ৔߹ ྫʣࣗಈंϝʔΧʔ ৗʹੜ࢈ίετΛ௿ݮ͢ΔΑ͏໨ࢦ͓ͯ͠Γɺࡏ ݿθϩઓུΛબ୒͢ΔϝʔΧʔ΋͋Δʢं͕ߪೖ ͞Ε͔ͯΒɺͦͷޙੜ࢈͢Δʣ ͜ͷ৔߹ɺ༨৒ࡏݿΛ๊͑ΔΑΓɺଈ࣌ൢചͷࡏ ݿ͕ͳ͍΄͏͕ྑ͍ͱ൑அ͞ΕΔ ԼৼΕͷઢΛҾ͍ͯɺ͜ͷ༧ଌͰҙࢥܾఆΛ͍ͨ͠

  9. Ҏ্ͷΑ͏ͳ৔߹ɺ͜ͷ༧ଌ۠ؒʢ্ৼΕɾԼৼΕʣ͕Θ͔ΔΑ͏ʹ ϞσϧΛ࡞੒ͨ͠΄͏͕ɺϏδωε՝୊ʹد༩Ͱ͖Δ৔߹͕͋Δ ༧ଌ۠ؒ

  10. 2. ༧ଌͷ৴པੑͷϞσϦϯά

  11. ఺ਪఆͰ͸ͳ͘ɺ্ৼΕɾԼৼΕΛਪఆ ͢ΔͨΊʹɺ༧ଌ۠ؒ΍෼෍ͷਪఆΛߦ ͍͍ͨ ࠓճ͸ɺ෼Ґ఺ͷਪఆΛߦ͏ࣄʹΑΓɺ ༧ଌ۠ؒͷਪఆΛߦ͏ख๏Λ঺հ͢Δ ༧ଌ͕۠ؒΘ͔Δ΄͔ʹɺͦͷ෼Ґ఺ʹ ͓͚Δภճؼ܎਺ͷมಈ΋Θ͔Δ ࣌ܥྻϞσϧʹ΋Ԡ༻Ͱ͖Δ ෼Ґ఺ճؼʢΫΦϯλΠϧճؼʣ

  12. 3. ϐϯϘʔϧଛࣦؔ਺

  13. ྫ͑͹ઢܗճؼͰ͸໨తؔ਺ʹೋ৐ޡࠩؔ਺Λ༻͍Δ ͕ɺ෼Ґ఺ճؼͰ͸୅ΘΓʹϐϯϘʔϧଛࣦؔ਺ʢඇ ରশઈରޡࠩؔ਺ʣΛ༻͍Δ ԼهͷΑ͏ʹॏΈ෇͚Λߦ͏ ࣮ଌ஋ͱ༧ଌ஋ͱͷࠩʢeʣ͕ਖ਼ͷͱ͖͸Н ࣮ଌ஋ͱ༧ଌ஋ͱͷࠩʢeʣ͕ෛͷͱ͖͸Н−̍ ϐϯϘʔϧଛࣦؔ਺ ඍ෼ՄೳͳͷͰɺ໨తؔ਺ͱͯ͠΋ධՁࢦඪͱͯ͠΋ ༻͍Δ͜ͱ͕Ͱ͖Δ τΛ0.5ͱ͢Δͱதԝ஋ͱͳΔ

  14. ϐϯϘʔϧଛࣦؔ਺ ϐϯϘʔϧͷϘʔϧͷيಓʹɹ ࣅ͍ͯΔ͔ΒΒ͍͠ ࣮෺ͷϐϯϘʔϧ τΛΫΦϯλΠϧͱͯ͠ఆٛʢ95%఺ͳΒ0.95ʣ͠ɺ Нͷൣғ಺͸ଛࣦ͕ޡ͕ࠩ௿͘ධՁ͞Εɺൣғ֎Ͱ͸ ޡ͕ࠩେ͖͘ධՁ͞ΕΔΠϝʔδ

  15. 4.ଛࣦؔ਺ʹΑΔ ෼Ґ఺ͷਪఆ

  16. ͜ͷଛࣦؔ਺ͷ࠷খԽΛߦ͏͜ͱͱɺ෼Ґ఺ͷਪఆΛߦ͏͜ͱ͕ಉٛ Ͱ͋Δ͜ͱ͸ɺ਺ֶతʹಋ͘͜ͱ͕Ͱ͖Δ https://en.wikipedia.org/wiki/Quantile_regression ϐϯϘʔϧଛࣦؔ਺ͷܭࢉ͸ɺ ͋Δ֬཰෼෍ʹै͏֬཰ม਺:ʢ࣮ଌ஋ʣͱ ෼Ґ఺Vͱͷࠩͷظ଴஋ͱݴ͍׵͑ͯ΋ྑ͍ ৔߹෼͚ʹैͬͯ෼ղ͢Δʢ཭ࢄ஋ͷ৔߹ʣ ࠷খԽ໰୊ͷͨΊɺVʹ͍ͭͯඍ෼ ਪఆ෼Ґ఺V R@aUBV

    ʹ͓͚Δ:ͷྦྷੵີ౓෼෍͕Нͱ౳͘͠ͳΔ
  17. 5. ར༻ՄೳͳϥΠϒϥϦ

  18. import statsmodels.formula.api as smf q = .975 mod = smf.quantreg('y

    ~ x', data) upper_mod = mod.fit(q=q) lower_mod = mod.fit(q=1-q) import lightgbm as lgb q = .975 clf_upper = lgb.LGBMRegressor(objective='quantile', alpha=q).fit(x, y) clf_lower = lgb.LGBMRegressor(objective='quantile', alpha=1-q).fit(x, y) # lossʹԼهͷΑ͏ͳϐϯϘʔϧଛࣦؔ਺Λఆٛͯ͠ࢦఆ͢Δ class QuantileLoss(nn.Module): def __init__(self, quantiles): super().__init__() self.quantiles = quantiles def forward(self, preds, target): assert not target.requires_grad assert preds.size(0) == target.size(0) losses = [] for i, q in enumerate(self.quantiles): errors = target - preds[:, i] losses.append( torch.max( (q-1) * errors, q * errors ).unsqueeze(1)) loss = torch.mean( torch.sum(torch.cat(losses, dim=1), dim=1)) return loss ઢܗϞσϧʢPython: statsmodelsʣ ޯ഑ϒʔεςΟϯάܾఆ໦ʢPython: Lightgbmʣ Deep LearningʢPython: Pytorchʣ ઢܗϞσϧʢR: quantreg R͸͍ͬͺ͍͋Δʣ library(quantreg) rq(y~x, data=data, tau=seq(0,1,0.25))
  19. ※KaggleͰ༧ଌ۠ؒਪఆͷίϯϖ͕։࠵த

  20. • R Koenker, Kf Hallock, Quantile Regression, Journal Of Economic

    Perspectives, 2001 • Wikipedia, Quantile Regression • Https://En.Wikipedia.Org/Wiki/Quantile_Regression • Lokad • Https://Www.Lokad.Com/Jp/෼Ґ஋༧ଌ-ٕज़ • Https://Www.Lokad.Com/Jp/ΫΥϯλΠϧ-ճؼ-ʢ࣌-ܥྻʣ-ఆٛ • Https://Www.Lokad.Com/Jp/ϐϯϘʔϧϩεػೳ-ఆٛ • ෼Ґ఺ճؼΛ࢖ͬͯɺʮͦͷճؼ༧ଌͲΕ͙Β͍֎ΕΔͷʁʯΛઆ໌͢Δ • Https://Devblog.Thebase.In/Entry/2018/12/06/110655 • Qrnn χϡʔϥϧωοτΛ༻͍ͨ෼Ґ఺ճؼ • Https://Aotamasaki.Hatenablog.Com/Entry/2019/01/29/191604 • ฏۉ͔Β෼Ґ఺΁ɿ෼Ґ఺ճؼ • Https://Www.N-Insight.Co.Jp/Niblog/20150903-1087/ • Quantile Regression — Part 2 • Https://Medium.Com/The-Artificial-Impostor/Quantile-Regression-Part-2-6Fdbc26B2629 ࢀߟ