我正在研究一个分类问题,其评估指标在ROC AUC中。到目前为止,我已尝试使用具有不同参数的xgb。这是我用来对数据进行采样的函数。您可以找到相关的笔记本here (google colab)
def get_data(x_train, y_train, shuffle=False):
if shuffle:
total_train = pd.concat([x_train, y_train], axis=1)
# generate n random number in range(0, len(data))
n = np.random.randint(0, len(total_train), size=len(total_train))
x_train = total_train.iloc[n]
y_train = total_train.iloc[n]['is_pass']
x_train.drop('is_pass', axis=1, inplace=True)
# keep the first 1000 rows as test data
x_test = x_train.iloc[:1000]
# keep the 1000 to 10000 rows as validation data
x_valid = x_train.iloc[1000:10000]
x_train = x_train.iloc[10000:]
y_test = y_train[:1000]
y_valid = y_train[1000:10000]
y_train = y_train.iloc[10000:]
return x_train, x_valid, x_test, y_train, y_valid, y_test
else:
# keep the first 1000 rows as test data
x_test = x_train.iloc[:1000]
# keep the 1000 to 10000 rows as validation data
x_valid = x_train.iloc[1000:10000]
x_train = x_train.iloc[10000:]
y_test = y_train[:1000]
y_valid = y_train[1000:10000]
y_train = y_train.iloc[10000:]
return x_train, x_valid, x_test, y_train, y_valid, y_test
以下是在混洗和非混洗数据上运行后得到的两个输出
AUC with shuffling: 0.9021756235738453
AUC without shuffling: 0.8025162142685565
你能在这里找出问题所在吗?
答案 0 :(得分:2)
问题在于,在实施改组时,np.random.randint
会生成随机数,但可以重复这些数字,因此您的列车和测试+有效集中会出现相同的事件。您应该使用np.random.permutation
代替(并考虑使用np.random.seed
来确保结果的可重复性。)
另一个注意事项 - 训练和验证/测试集之间的性能差异非常大(训练显示几乎完美的ROC AUC)。我猜,这是因为树的最大深度太高(14),你允许你拥有的数据集大小(~60K)
P.S。感谢分享协作链接 - 我不知道它,但它非常有用。