我有高度不平衡的数据。 而我想通过拆分数据和欠采样来解决二分类问题。
1.我有类似下面代码的数据。
输入:data.columns
输出:
Index(['DLQ_CD', 'LN_AMT101_1912', 'LN_AMT105_1912', 'LN_AMT107_1912',
'LN_AMT109_1912', 'LN_AMT115_1912', 'LN_AMT117_1912', 'LN_AMT129_1912',
'LN_CNT101_1912', 'LN_CNT105_1912', 'LN_CNT107_1912', 'LN_CNT109_1912',
'LN_CNT115_1912', 'LN_CNT117_1912', 'LN_CNT129_1912'],
dtype='object')
2.数据高度不平衡。
输入:
neg, pos = np.bincount(data['DLQ_CD'])
total = neg + pos
print('Examples:\n Total: {}\n Positive: {} ({:.2f}% of total)\n'.format(
total, pos, 100 * pos / total))
输出:
Examples:
Total: 382116
Positive: 477 (0.12% of total)
3.在教程方面,我们可以拆分数据集以获得训练/测试/有效数据集。 (https://www.tensorflow.org/tutorials/structured_data/imbalanced_data)
输入:
train_df, test_df = train_test_split(cleaned_df, test_size=0.2)
train_df, val_df = train_test_split(train_df, test_size=0.2)
train_labels = np.array(train_df.pop('DLQ_CD'))
bool_train_labels = train_labels != 0
val_labels = np.array(val_df.pop('DLQ_CD'))
test_labels = np.array(test_df.pop('DLQ_CD'))
train_features = np.array(X_train)
val_features = np.array(val_df)
test_features = np.array(test_df)
但是,我不知道如何对训练/测试/有效数据进行欠采样。
我尝试使用下面的代码来解决问题,但它不起作用..
from imblearn.under_sampling import RandomUnderSampler
#UnderSampler 정의
rus = RandomUnderSampler(random_state=10)
rus.fit(X_train,y_train)
X_train_under,y_train_under = rus.fit_resample(X_train,y_train)
这对我来说很重要,但我真的不知道如何解决..
请帮帮我!