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

分位点回帰 / quantile regression

jeey
May 29, 2020

分位点回帰 / quantile regression

jeey

May 29, 2020
Tweet

More Decks by jeey

Other Decks in Science

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. 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))
  3. • 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 ࢀߟ