Regression - IBUG 알고리즘 논문 읽기

    목차
반응형

1. 소개

- arxiv.org/pdf/2205.11412v2.pdf

- GitHub - jjbrophy47/ibug: Instance-based uncertainty estimation for gradient-boosted regression trees

- IBUG = Instance-Based Uncertainty estimation for Gradient-boosted regression trees

- Boost 계열의 regression tree 모델(XGBoost, LightGBM, CatBoost 등)의 예측값을 확률로 보여주기 위한 알고리즘

 

2. 요약

1. 앙상블 tree 계열 모델로 데이터를 학습
2. 내가 찾고자 하는 데이터 X가 각 트리의 어느 리프에 있는지, 그리고 어떤 데이터들이 그 리프 안에 속해있는지 확인
3. 그 중에서 가장 많이 밀접한 k개의 학습 데이터를 모음
4. 3에서 모은 데이터의 평균과 분산으로 확률 계산

 

 

3. Notation & Background

- instance space $\mathcal{X} \subseteq \mathbb{R}^p$
- target space $\mathcal{Y} \subset \mathbb{R}$
- Let $D:= \{ (x_i, y_i) \}^n_{i=1}$ be a training dataset in which each instance $x_i \in \mathcal{X}$ is a $p$-dimensional vector $(x_i^j)^p_{j=1}$ and $y_i \in \mathcal{Y}$

 

 

4. Instance-Based Uncertainty

4-1. Identification of High-Affinity Neighbors

- Instance간 얼마나 밀접한지(affinity)를 확인하기 위한 공식
    - $A(x_i, x_{te}) = \sum \limits_{i=1}^T \mathbb{1}[R_t(x_i)=R_t(x_{te})]$
    - $R_t(x_i)$는 트리 $t$에서 $x_i$가 있는 잎(leaf)

 

4-2. Modeling the Output Distribution

- 예측값(평균) $\mu_{\hat{y}_{te}}=f(x_{te})$
- $x_{te}$와 유사한 $k$개의 데이터 집합 $A^{(k)}$의 분산 $\sigma_{\hat{y}_{te}}^2$

 

Calibrating prediction variance

- 일부 데이터셋에 대해 분산은 클 수도, 작을 수도 있기 때문에 검증 데이터를 이용하여 분산 값을 교정한다.
- $\sigma_{\hat{y}_{te}}^2 \leftarrow \gamma \sigma_{\hat{y}_{te}}^2 + \delta$
    - $\gamma$, $\delta$는 $k$가 정해진 뒤 검증 데이터로 맞춰지는 값
    - $\gamma$를 튜닝하기 위해 $\delta=0$으로 놓거나 $\delta$를 튜닝하기 위해 $\gamma=1$으로 놓고 검증 데이터에 대한 성능이 가장 좋도록 값을 찾아간다.

 

Flexible posterior modeling

- $\hat D_{te}=D\left(A^{(k)}|\mu_{\hat{y}_{te}},\sigma_{\hat{y}_{te}}^2\right)$
    - $D$: 연속 분포(continuous distribution)
    - $D$는 MLE(maximum likelihood estimation)을 이용한 $A^{(k)}$로 직접 맞춰지거나(fit directly)
    - 또는 $\mu_{\hat{y}_{te}}$나 $\sigma_{\hat{y}_{te}}^2$를 고정된 파라미터 값으로 사용하고 $A^{(k)}$는 분포의 다른 파라미터에 맞춰짐

 

 

5. Computational Efficiency

 

 

6. 예시 코드

from ibug import IBUGWrapper
from xgboost import XGBRegressor
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split

# load diabetes dataset
data = load_diabetes()
X, y = data['data'], data['target']

# create train/val/test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=1)
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.1, random_state=1)

# train GBRT model
model = XGBRegressor().fit(X_train, y_train)

# extend GBRT model into a probabilistic estimator
prob_model = IBUGWrapper().fit(model, X_train, y_train, X_val=X_val, y_val=y_val)

# predict mean and variance for unseen instances
location, scale = prob_model.pred_dist(X_test)

# return k highest-affinity neighbors for more flexible posterior modeling
location, scale, train_idxs, train_vals = prob_model.pred_dist(X_test, return_kneighbors=True)


upper = location + 2.58*scale
lower = location - 2.58*scale


import matplotlib.pyplot as plt

p1 = plt.plot(y_test)
p2 = plt.plot(location)

h = plt.fill_between(range(len(y_test)), lower, upper, color='orange', alpha=0.1)

plt.legend([p1, p2, h], labels=['Real', 'Pred', 'Prob (99%)'])
plt.show()

728x90
반응형