[ML]ターゲットアンバランス/オーバーサンプリング/アンダーサンプリング
5883 ワード
1.目標アンバランス(分類)
多くの場合、
1) class_weight
#balanced 옵션으로 비율을 조정
DecisionTreeClassifier(max_depth=5, class_weight='balanced', random_state=2)
#비중을 직접 계산하여 비율을 조정
custom = len(y_train)/(2*np.bincount(y_train))
custom
DecisionTreeClassifier(max_depth=5, class_weight={False:custom[0],True:custom[1]}, random_state=2)
XGBClassifier(n_estimators=1000, verbosity=0, n_jobs=-1, scale_pos_weight=ratio)
#ratio = sum(negative instances) / sum(positive instances)
2) Neighbor-based approaches
3) SMOTE
sm = SMOTE(ratio='auto', kind='regular')
X_resampled, y_resampled = sm.fit_resample(X_train, y_train)
2.目標分布のアンバランス(回帰)
#numpy를 활용한 로그변환
import numpy
log1p()
expm1()
#TransformedTargetRegressor를 활용한 로그변환
tt = TransformedTargetRegressor(regressor=pipe,
func=np.log1p, inverse_func=np.expm1)
Reference
この問題について([ML]ターゲットアンバランス/オーバーサンプリング/アンダーサンプリング), 我々は、より多くの情報をここで見つけました https://velog.io/@gooook/ML-Target-불균형-Over-sampling-Under-samplingテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol