当前位置: 代码迷 >> 综合 >> shuffle data 随机打乱数据集数据
  详细解决方案

shuffle data 随机打乱数据集数据

热度:98   发布时间:2023-11-24 12:28:29.0

文章目录

  • shuffle data

shuffle data

随机打乱数据

将数据随机打乱后再训练,有助于模型的训练,否则模型应该更倾向于预测为后半部分的分类(二分类问题中)

import randomdef shuffleData(X, y, seed=None):random.seed(seed)index = [i for i in range(len(X))]random.shuffle(index)print(index)X = X[index]y = y[index]return X, ydef shuffle_data_list_dict(data_list_dict: dict, seed=None):train_X, train_y = shuffleData(data_list_dict["train_X"], data_list_dict["train_y"], seed)test_X, test_y = shuffleData(data_list_dict["test_X"], data_list_dict["test_y"], seed)return {'train_X': train_X, 'train_y': train_y, 'test_X': test_X, 'test_y': test_y}
  相关解决方案