Gausian Mixture Anomaly detection

<수업>/과제|2022. 5. 4. 17:14
반응형

Anomaly detection 종류

  1. Supervised Anomaly Detection  : 트레이닝 데이터에 비정상,정상 Label이 모두 적절히존재했을 때
  2. Semi-supervised Anomaly Detection : 정상 데이터만을 가지고 학습한 경우 (비정상 라벨이 심각하게 적은경우)
  3. Unsupervised Anomaly Detection : 트레이닝 데이터에 정상, 비정상 Labeling이 안 된 경우

 

X_train = x_m
y_train = y_m  # 라벨
X_test = x_f
y_test = y_f # 라벨
X_val = x_w
Y_val = y_w # 라벨

gmm_clf = GaussianMixture(covariance_type='full', n_components=3 ,max_iter=int(1e5))  # Obtained via grid search
# covariance_type : full  tied  diag  spherical
gmm_clf.fit(X_train)
log_probs_val = gmm_clf.score_samples(X_val)
isotonic_regressor = IsotonicRegression(out_of_bounds='clip')
isotonic_regressor.fit(log_probs_val, Y_val)  

log_probs_test = gmm_clf.score_samples(X_test)
test_probabilities = isotonic_regressor.predict(log_probs_test)
test_predictions = [1 if prob >= 0.5 else 0 for prob in test_probabilities]

cm = confusion_matrix(y_test,test_predictions )
print(cm)
print(accuracy_score(y_test,test_predictions))
sns.heatmap(cm,annot=True,fmt='g')

covariance_type 매개변수에 다음 값 중 하나를 설정  

  1. "spherical”: 모든 클러스터가 원형이지만 지름은 다를 수 있음(분산이 다름) 
  2. "diag”: 클러스터는 크기에 상관없이 어떤 타원형도 가능하지만 타원의 축은 좌표 축과 나란핬야 함(공분산 행렧이 대각 행렧이어야 함)  
  3. "tied”: 모듞 클러스터가 동일한 타원 모양, 크기, 방향을 가짐(모든 클러스터는 동일핚 공분산 행렧을 공유)  
  4. full” : covariance_type 매개변수의 기본값은 "full" 인데 각 클러스터는 모양, 크기, 방향에 제약이 없음(각자 제약이 없는 공분산 행렧을 가짐)

 

 

 

 

반응형

댓글()