gpt4 book ai didi

python - 为什么在相同数据和相同算法上评估时会产生两个不同的 AUC 分数

转载 作者:行者123 更新时间:2023-12-01 01:49:55 26 4
gpt4 key购买 nike

我正在研究一个分类问题,其评估指标为 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

你能找出这里的问题是什么吗?

最佳答案

问题是,在您的洗牌实现中 - np.random.randint 生成随机数,但它们可以重复,因此您的训练和测试+有效集中会出现相同的事件。您应该使用 np.random.permutation (并考虑使用 np.random.seed 以确保结果的可重复性)。

另一个注意事项 - 训练集和验证/测试集之间的性能差异非常大(训练显示几乎完美的 ROC AUC)。我猜,这是由于树的最大深度 (14) 太高,您手头的数据集大小 (~60K) 是允许的

附注感谢您分享合作链接 - 我不知道它,但它非常有用。

关于python - 为什么在相同数据和相同算法上评估时会产生两个不同的 AUC 分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50831605/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com