Dataset Shift에 대한 이해 (4) - Identifying Dataset Shift, Handling Dataset Shift (실용 파트)

2019. 12. 17. 00:27관심있는 주제/분석 고려 사항

728x90

https://towardsdatascience.com/understanding-dataset-shift-f2a5a262a766

Dataset Shift에 대한 이해 (1) - Covariate Shift

Dataset Shift에 대한 이해 (2) - Prior probability Shift, Concept Drift

Dataset Shift에 대한 이해 (3) - Internal Covariate Shift, Sample selection bias, Non -stationary environments

 

Identifying Dataset Shift

데이터 세트에 이동이 있는지 여부와 그 심각도를 결정하는 데 사용할 수 있는 몇 가지 방법이 있다.

일부 프로덕션 시스템에서는 사후 분석을 수행할 필요가 없기 때문에 비지도 방법들은 아마도 dataset shift를 인지하는 유용한 방법들이다. 
모델 운영시 오류 증가와 외부 홀드 아웃의 성능을 근본적으로 살펴보는 지도 방법들이 존재한다. (validation set)

1) Statistical Distance

The statistical distance 방법은 만약 모델 예측이 시간이 갈수록 변하는 것을 탐지할 때 유용하다.
이것은 histograms를 사용하고 만듦으로써 할 수 있다.  히 스트로그램들을 만듦으로써, 당신은 당신의 모델 예측이 시간에 따라 변하는지를 탐지할 수 있을 뿐만 아니라, 당신의 가장 중요한 특징들이 시간에 따라 변하는지도 확인할 수 있다.
간단히 말해 훈련 데이터의 히스토그램을 만들고 시간에 따라 추적하고 변화를 보기 위해 비교하는 것이다.
이 방법은 흔히 금융 기관들이 신용 점수 모델에 흔히 사용된다.

시간이 갈수록 모델 예측들의 변화를 감시하는 몇몇의 메트릭이 있다.
These include the Population Stability Index (PSI)Kolmogorov-Smirnov statisticKullback-Lebler divergence (or other f-divergences), and histogram intersection

이 방법의 주요한 단점은 고차원이나 희소한 특징에서는 좋지 않다. 
그러나 이러한 이슈를 다룰 때 시도해야할 가장 첫 번째라고 생간 한다.

2) Novelty Detection


컴퓨터 비전과 같이 상당히 복잡한 도메인에 더 쉽게 적응할 수 있는 방법은 Novelity detection이다.
이 아이디어는 Source 분포를 모델링하는 모델을 만든 것이다. 

새로운 데이터가 주어졌을 때, source 분포로부터 뽑은 데이터 포인트의 가능성을 시도해라.
이러한 방법으로 다양한 기술을 사용한다 (one-class supprot vector machine)

만약 당신이 동일하지만 매우 복잡한 상호 작용(예: 시각, 오디오 또는 원격 감지)의 상태를 다룰 경우, 이 방법을 검토해야 한다. 그 경우 통계적 거리(히스토그램 방법)가 방법만큼 효과적이지 않기 때문이다.

이 방법의 가장 큰 단점은 무엇이 변했는지 분명히 말할 수 없고 다만 변화가 있었다는 것이다.

3) Discriminative Distance

The discriminative distance method은 덜 흔하다. 그럼에도 불구하고 그것은 효과적이다.
직관은 어떤 분류자를 훈련시켜 예시가 소스 도메인에서 왔는지 또는 대상 도메인에서 왔는지를 탐지하고자 하는 것이다. 그 두 개 분포 사이의 거리의 프락시가 되는 훈련 오류 사용할 수 있다. 에러가 높을수록 그들은 가까워졌다. 즉 분류기는 source와 target domain사이에서 구별을 못한다. 

Discriminative distance은 고차원 데이터에서 넓게 사용된다. 비록 이것은 시간이 많이 들고 매우 복잡하지만, 이 방법은 domain 적응인지 아닌지 유용한 기술이다. (and for some deep learning methods, this may be the only feasible technique that exists).
이 방법은 고차원과 sparse data에 좋다. 그리고 넓게 이용 가능하다.
그러나 오프라인에서만 할 수 있고 이전 방식보다 구현이 더 복잡하다.


Handling Dataset Shift

Dataset Shift을 어떻게 수정하십니까? 
가능하다면, 항상 재학습을 해야 한다. 물론 몇몇 상황에서는 가능하지 않을 것이다.
예를 들어, 만약 재학습 시 latency 문제들이 있다.
이러한 경우 몇몇 dataset shift를 수정하는 몇 개의 기술이 있다.

1) Feature Removal

covariate shift를 식별하기 위해 위에서 설명한 statistical distance를 활용함으로써, 변화의 정도를 측정할 수 있다.
우리는 shift의 납득할 만한 수준을 경계선을 세울 수 있다.  개별 형상을 분석하거나 절제 연구를 통해 어떤 형상이 데이터 집합에서 이러한 변화를 가장 많이 발생시키는지를 결정할 수 있다.

기대했던 대로, covariate shift와 연관된 변수를 제거하는 것과 추가적인 변수를 더하는 것 그리고 몇몇 covariate shift를 묵인하는 것 사이에는 trade-off가 있다.
이 trade-off는 데이터 과학자가 케바케 원칙을 가질 필요가 있다.
train과 test 중에 많이 다르지만 예측력을 많이 주지 않는 특징은 항상 버려야 한다.

예로, PSI는 risk management에 사용된다. 그리고 0.25라는 임의적인 값은 제한선으로 사용된다. 

2) Importance Reweighting

재가 중 중요성이 잇는 주요 아이디어는 test instances와 매우 유사한 training instance를 상향 조정하고자 한다는 것이다. 본질적으로, test data set 뽑아낸 것과 같은  training data set의 변화를 시도할 수 있다. 
방법에 필요한 것은 시험 도메인에 대한 라벨이 없는 예시뿐이다. 이 경우 시험 세트에서 데이터가 누출될 수 있다.

On the left, we have our typical training set and in the center our test set. We estimate the data probability of the training and test sets and use this to rescale our training set to produce the training set on the right (notice the size of the points has got larger, this represents the ‘weight’ of the training example).

To make it clear how this works, we basically reweight each of the training examples by the relative probability of the training and test set. We can do this by density estimation, through kernel methods such as kernel mean matching, or through discriminative reweighting.

3) Adversarial Search

The adversarial search method uses an adversarial model where the learning algorithm attempts to construct a predictor that is robust to the deletion of features at test time.

The problem is formulated as finding the optimal minimax strategy with respect to an adversary which deletes features and shows that the optimal strategy may be found by either solving a quadratic program or using efficient bundle methods for optimization.

Covariate shift has been extensively studied in the literature, and a number of proposals to work under it have been published. Some of the most important ones include:

 

  • Weighting the log-likelihood function (Shimodaira, 2000)
  • Importance weighted cross-validation (Sugiyama et al, 2007 JMLR)
  • Integrated optimization problem. Discriminative learning. (Bickel et al, 2009 JMRL)
  • Kernel mean matching (Gretton et al., 2009)
  • Adversarial search (Globerson et al, 2009)
  • Frank-Wolfe algorithm (Wen et al., 2015)

Final Comments

Dataset shift is a topic that is, in my estimation, extremely important and yet undervalued by people in the field of data science and machine learning.

Given the impact it can have on the performance of our algorithms, I suggest spending some time working out how to handle data properly in order to give you more confidence in your models, and, hopefully, superior performance.

 

갈수록 어렵~

728x90