MachineLearning

Imbalanced data를 처리하는 기술 7가지

쌍쌍바나나 2017. 8. 27. 22:20
반응형

7 Techniques to Handle Imbalanced Data

  • intrusion detection
  • real-time bidding

Introduction

  • fraud detection in banking
  • real-time bidding in marekting
  • intrusion detection in networks

    위 분야에서는 1%보다 낮게 interesting의 events가 포함되어 있다. (예를 들면 fraudsters using credit cards, clicking advertisement, corrupted server scanning its network)
    그러나 머신러닝 알고리즘에서는 imbalanced datasets에 대해서 처리를 잘 하지 못한다. 아래 7개의 techniques은 abnormal class를 detect하기 위한 classifier를 학습하는데 도움을 줄것이다.

1.Use the right evaluation metrics

imbalanced data를 사용해서 model을 생성하게 되면 evaluation metrics를 부적절하게 해석을 할 수 있기 때문에 매우 위험하다. 0이 데이터의 99%를 차지한다면, 모델의 정확도는 99%를 보여줄것이다. 하지만 이 정확도는 가치있는 정확도가 아니다.

이러한 경우에는, 다른 대체 가능한 evaluation metrics를 사용하는게 좋다.

  • Precision/Specificity: how many selected instances are relevant
  • Recall/Sensitivity: how many relevant instances are seleted.
  • F1 score: harmonic mean of precision and recall
  • MCC: correlation coeeficient between the observed and predicted binary classifiations
  • AUC: relation between true-positive rate and false positive rate

2.Resample the training set

undersampling과 over-sampling을 통해서 balanced dataset으로 resampling을 하는 방법이 있다.

2.1. Under-sampling

abundant class의 사이즈를 줄여서 balanced dataset으로 만드는것을 말한다. 이 방법은 데이터의 양이 충분할때 사용할 수 있는 방법이다. rare class의 모든 샘플을 keeping하고, abudant class의 샘플들의 숫자를 랜덤으로 선택해서 숫자를 같게 만드는 방법이다.

2.2. Over-sampling

데이터의 양이 충분하지 않을때 사용하는 방법으로, rare sample의 사이즈를 증가시켜 balanced dataset으로 만드는 것이다. 새로운 rare samples을 생성하기 위해서는 repetition, bootstrapping, SMOTE(Synthetic Minority Over-Sampling Technique)를 사용하면 된다.

하나의 리샘플링 방법이 다른 리샘플링 방법보다 절대적인 이점은 없다. 이 두 가지 방법의 적용은 적용되는 사용 사례와 데이터 세트 자체에 따라 다르다. Over-, under-sampling을 조합하면 종종 좋은 결과를 보여준다.

3.Use K-fold Cross-VAlidation in the right way

over-sampling을 사용할때 적절한 방법이다. over-sampling은 rare samples의 distribution function을 기반으로 새로운 random data를 생성하기 위해서 bootstrapping을 적용하게 된다. 만약 cross-validation이 over-sampling이후에 적용이 되면, 기본적으로 우리가하고 것은 우리의 모델을 특정 artificial bootstrapping 결과에 맞추는 것이다. cross-validation은 over-sampling을 하기 전에 항상 완료가 되어야 한다.

4.Ensemble different resampled datasets

더 많은 데이터를 사용해서 model을 성공적으로 generalize하기 위한 가장 쉬운 방법이다. 이 문제는 out-of-the-box classifier같은 logistic regression, random forest와 같이 rare class를 버리기 위해 generalize를 하는 경향이 있다. rare class의 모든 샘플들과, abundant class의 n-differing samples을 사용해서 n 개의 models을 building을 해보자. 10개의 ensemble models이 만들어 질것이다. (1000개의 rare class, 10,000개의 abundant class) 10,000개를 10개의 chunks로 split을 해서 10개의 다른 모델을 train한다.

이 방법은 심플하고 데이터가 많아도 완벽하게 horizontally scalable다. 또한 다른 클러스터의 노드들에서 각각의 모델을 학습할 수 있다는게 장점이다. ensemble models은 또한 generalize better, approach도 쉽다.

5.Resample with different ratios

이전의 approach는 rare와 abundant class사이에 fine-tune이 가능하다. best ratio는 data에 의존적이고 그 모델은 사용이 된다. 그러나 ensemble에서 같은 ratio를 사용한 모든 모델을 train을 하는 대신에, different ratios를 ensemble하는게 더 좋다. 10개의 모델을 train을 했다면, 하나는 1:1, 나머지는 1:3, 2:1로. 사용 된 모델에 따라 하나의 클래스가 얻는 가중치에 영향을 줄 수 있습니다.

6.Cluster the abundant class

tranining samples의 variety를 커버하기 위해서 random samples을 사용하는 대신에, clustering을 통해 abundant class를 r groups으로 clustering을 하는 것을 제안했다. r에 있는 classes의 개수를 r로. 각 그룹에 대해서, medoid(centre of cluster)에 유지 된다. 그 모델은 rare class와 medoids로 부터 trained 된다.

7.Design your own models

cost function을 design해라!

만약 모델이 imbalanced data에 적절하다면, resample은 필요가 없다. 유명한 XGBoost는 내부적으로 imbalanced가 되지 않도록 trains을 하기 때문에 이미 class가 너무 많이 skewed가 되지 않았다면 좋은 결과를 준다. 그러나 그 다음 다시 data가 resampled되면 안좋다는거야 뭐야…

abundant class의 잘못된 classification보다 rare class의 잘못된 classification이 더 penalizing하다. cost function을 설계함으로써, rare class의 favour(편애)에서 naturally generalize를 할 수 있다. 예를 들어서 SVM을 tweaking(조정)을 한다. penalize하기 위해서 rare class의 잘못된 분류를. 같은 ratio

Final Remarks

위의 방법들은 starting points로 시작하면 된다.

반응형