데이터셋 시프트

Python으로 설계하는 Machine Learning 워크플로

Dr. Chris Anagnostopoulos

Honorary Associate Professor

데이터셋 시프트란?

elec 데이터셋:

  • 2년치 데이터
  • class=1은 지난 24시간 대비 가격이 상승, 0은 하락
   day    period  nswprice  ...    vicdemand  transfer  class
0    2  0.000000  0.056443  ...     0.422915  0.414912      1
1    2  0.553191  0.042482  ...     0.422915  0.414912      0
2    2  0.574468  0.044374  ...     0.422915  0.414912      1

[3 rows x 8 columns]
Python으로 설계하는 Machine Learning 워크플로

무엇이 어떻게 변하나요?

곡선 결정 경계로 분리된 2차원상의 두 클래스.

Python으로 설계하는 Machine Learning 워크플로

무엇이 어떻게 변하나요?

곡선 결정 경계로 분리된 두 클래스, 옆에는 유사한 위치의 클래스지만 다른 형태의 결정 경계를 가진 그림.

Python으로 설계하는 Machine Learning 워크플로

윈도우

슬라이딩 윈도우

window = (t_now-window_size+1):t_now
sliding_window = elec.loc[window]

최근 데이터만 강조된 데이터셋.

확장 윈도우

window = 0:t_now
expanding_window = elec.loc[window]

터미널에 표시된 데이터셋.

Python으로 설계하는 Machine Learning 워크플로

데이터셋 시프트 감지

# t_now = 40000, window_size = 20000
clf_full = RandomForestClassifier().fit(X, y)
clf_sliding = RandomForestClassifier().fit(sliding_X, sliding_y)
# 미래 데이터를 테스트로 사용
test = elec.loc[t_now:elec.shape[0]]
test_X = test.drop('class', 1); test_y = test['class']
roc_auc_score(test_y, clf_full.predict(test_X))
roc_auc_score(test_y, clf_sliding.predict(test_X))
0.775
0.780
Python으로 설계하는 Machine Learning 워크플로

윈도 크기

for w_size in range(10, 100, 10):
    sliding = arrh.loc[
      (t_now - w_size + 1):t_now
    ]
    X = sliding.drop('class', 1)
    y = sliding['class']
    clf = GaussianNB()
    clf.fit(X, y)
    preds = clf.predict(test_X)
    roc_auc_score(test_y, preds)

창 크기에 따른 AUC를 그리면, 창=50에서 최대 0.83까지 증가했다가 다시 감소함을 보인다.

Python으로 설계하는 Machine Learning 워크플로

도메인 시프트

arrhythmia 데이터셋:

   age  sex  height  ...    chV6_TwaveAmp  chV6_QRSA  chV6_QRSTA  class
0   75    0     190  ...              2.9       23.3        49.4      0
1   56    1     165  ...              2.1       20.4        38.8      0
2   54    0     172  ...              3.4       12.3        49.0      0
3   55    0     175  ...              2.6       34.6        61.6      1
4   75    0     190  ...              3.9       25.4        62.8      0

[5 rows x 280 columns]
Python으로 설계하는 Machine Learning 워크플로

데이터가 많다고 항상 좋은 것은 아님!

Python으로 설계하는 Machine Learning 워크플로

Preparing Video For Download...