jeey
May 29, 2020
21

# 分位点回帰 / quantile regression

May 29, 2020

## 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 ෼Ґ఺ ճؼ

Λͱͬͯҙࢥܾఆ͍ͨ͠

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

ʹ͓͚Δ:ͷྦྷੵີ౓෼෍͕Нͱ౳͘͠ͳΔ

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))

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 ࢀߟ