오늘로 머신러닝 파트가 끝이 났다. 이상탐지 부분이 어려운 개념들이 많아서 진이 많이 빠졌지만 어려운만큼 이후에 도움이 될 거라고 생각해서 열심히 들었던 것 같다.
inverse_transform : 주성분 점수를 원본 데이터 형태로 복원X_hat = model_pca.inverse_transform(pca_score)
residual = X_scaled - X_hat
spe = (residual ** 2).sum(axis=1)
spe_threshold = np.quantile(a=spe, q=1-fail_rate)
spe_outlier = (spe > spe_threshold)
spe_outlier.sum()
# np.int64(339)
df.loc[spe_outlier, 'Target'].value_counts(normalize=True).sort_index()
# Target
# 0 0.666667
# 1 0.333333
# Name: proportion, dtype: float64
from sklearn.ensemble import IsolationForest
iso = IsolationForest(
n_estimators=100,
contamination=fail_rate,
random_state=0
)
iso.fit(X=train_num)
iso_pred = iso.predict(X=train_num)
iso_outlier = (iso_pred == -1)
iso_outlier.sum()
# np.int64(339)
df.loc[iso_outlier, 'Target'].value_counts(normalize=True).sort_index()
# Target
# 0 0.855457
# 1 0.144543
# Name: proportion, dtype: float64
from sklearn.svm import OneClassSVM
ocs = OneClassSVM(nu=fail_rate)
ocs.fit(X=X_scaled)
ocs_pred = ocs.predict(X=X_scaled)
ocs_outlier = (ocs_pred == -1)
ocs_outlier.sum()
# np.int64(340)
df.loc[ocs_outlier, 'Target'].value_counts(normalize=True).sort_index()
# Target
# 0 0.711765
# 1 0.288235
# Name: proportion, dtype: float64
내일은 깃허브 특강이 있는 날이다. 매번 깃허브를 그냥 구글 드라이브처럼 사용하기만 해서 협업할 때 사용하는 기능들에 대해 많이 배우면 좋겠다.