Sejong-Kaggle-Challengers / jeongmin

📌 Sejong Kaggle Challenger 이정민 레퍼지토리
0 stars 0 forks source link

[8주차] 원자력발전소 상태 판단 #8

Open mingxoxo opened 3 years ago

mingxoxo commented 3 years ago

https://dacon.io/competitions/official/235551/overview/

mingxoxo commented 3 years ago

GirdSearch

Random Search

image

출처 : https://shwksl101.github.io/ml/dl/2019/01/30/Hyper_parameter_optimization.html

Bayesian Optimization

posterior(데이터가 주어졌을 때 모델) ∝ likelihood(추가적 실험정보) × prior(현재까지 얻어진 모델)

참고출처 및 자세한 내용 : Bayesian Optimization|작성자 mutex , 자세한 이론

mingxoxo commented 3 years ago

불필요한 column 삭제

이 대회는 column이 많은 것이 특징이다. 따라서 약 5000여개의 column에서 row에 따라 값이 변하지 않는 column은 의미없는 column으로 간주하여 해당 column을 삭제하는 작업을 진행한다.

1) 유니크한 값의 개수가 1인 column을 제거하는 방식 --> 1783개가 삭제됨 2) 표준편차가 0인 column을 제거하는 방식 --> 1693개가 삭제됨 --> 성능이 미세한 차이로 우수

데이터 리샘플링

110개의 라벨의 경우 약 24여개의 데이터가 포함, 일부 라벨은 1개의 데이터만 포함된 경우도 더러 있음 데이터의 불균형한 분포를 해결하기 위해 리샘플링을 진행한다.

1) 적은 클래스의 비중을 높이거나(Over-Sampling) --> 최소값인 1개로 재 할당 2) 다수를 차지하는 클래스를 줄이는 방법(Under-Sampling) --> 최대값인 24개로 재 할당

#라벨 별 분포도 확인하기
warnings.filterwarnings(action='ignore')
plt.figure(figsize=(20, 50))
sns.countplot(y=y_train)
plt.title('N of data allocation by label \n', size=20)
plt.grid()

plt.show()

차원 축소

PCA 사용 --> 성능이 저하되어서 적절하지 않다고 판단했다.

이상치 탐색 - lsolation forest

이상 탐지 : 자료에서 다른 패턴을 보이는 자료를 찾는 것

  1. Point anomaly : 데이터셋 내에 하나의 데이터가 나머지에 대해 이상하다고 판단되는 경우, 흔히 아웃라이어(Outlier)라고 부른다.
  2. Collective anomaly : 데이터셋 내에 여러 데이터 포인트가 이상하다고 판단되는 경우
  3. Contextual anomaly : 전체적인 데이터셋의 맥락을 고려했을때 이상하다고 판단되는 경우

lsolation forest : 밀도 기반으로 이상 탐지 데이터셋을 의사결정나무 형태로 표현해 정상값을 분리하기 위해서는 의사결정나무를 깊숙하게 타고 내려가야 하고, 반대로 이상값은 의사결정나무 상단부에서 분리할 수 있다는 것을 이용

from sklearn.ensemble import IsolationForest

image

from sklearn.ensemble import IsolationForest
clf=IsolationForest(n_estimators=50, max_samples=50, contamination=float(0.004), 
                        max_features=1.0, bootstrap=False, n_jobs=-1, random_state=None, verbose=0,behaviour="new")
# 50개의 노드 수, 최대 50개의 샘플
# 0.4%의 outlier 색출.
clf.fit(feature_set)
pred = clf.predict(feature_set)
feature_set['anomaly']=pred
outliers=feature_set.loc[feature_set['anomaly']==-1]
outlier_index=list(outliers.index)
#print(outlier_index)
#Find the number of anomalies and normal points here points classified -1 are anomalous
print(feature_set['anomaly'].value_counts())

출처 : https://partrita.github.io/posts/isolation-forest/#2.3.-Contextual-anomaly https://john-analyst.medium.com/isolation-forest%EB%A5%BC-%ED%86%B5%ED%95%9C-%EC%9D%B4%EC%83%81%ED%83%90%EC%A7%80-%EB%AA%A8%EB%8D%B8-9b10b43eb4ac