【问题标题】:Why two different AUC scores are produced when evaluated on same data and same algorithm为什么在对相同数据和相同算法进行评估时会产生两个不同的 AUC 分数
【发布时间】:2018-11-22 16:53:13
【问题描述】:

我正在研究一个分类问题,其评估指标为 ROC AUC。到目前为止,我已经尝试使用具有不同参数的 xgb。这是我用来采样数据的函数。并且可以找到相关的notebookhere (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

你能找出这里的问题吗?

【问题讨论】:

  • 可能是欠拟合?因此准确性取决于随机因素(例如训练程序中的评估顺序)而不是预测参数。

标签: python xgboost auc


【解决方案1】:

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

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

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

【讨论】:

  • 好像是这个原因,我需要调查一下
  • 在创建随机播放数据后,我添加了一些检查
  • 尝试使用排列,但两种 AUC 仍然存在很大差异。虽然你的回答被接受了。如果您还有其他内容,请在笔记本中更新。
猜你喜欢
  • 1970-01-01
  • 2021-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-07
  • 1970-01-01
  • 2020-05-14
  • 2021-02-19
相关资源
最近更新 更多