1. np.random_choice(array, len)  进行随机的数据选择,array表示抽取的对象,len表示抽取样本的个数

数据的下采样是对多的数据进行np.random.choice 随机的抽取,抽取出于少的样本相同的索引个数,将两组索引进行合并,从原始数据中重新取值

# 2 进行数据的下采样

negtive_len = len(data[data.Class==1])
negtive_index = data[data.Class==1].index

# 获得正常样本的数据便签
normal_len = len(data[data.Class==0])
normal_index = data[data.Class==0].index
# 随机抽取
under_normal_index = np.random.choice(normal_index, negtive_len)
# 将两个样本的索引进行合并
under_index = np.concatenate([negtive_index, under_normal_index])

under_data = data.iloc[under_index, :]
under_x = under_data.loc[:, under_data.columns != 'Class']
under_y = under_data.loc[:, under_data.columns == 'Class']

 

相关文章:

  • 2021-04-25
  • 2021-12-08
  • 2021-07-05
  • 2021-12-04
猜你喜欢
  • 2022-12-23
  • 2021-09-16
  • 2021-10-26
  • 2021-10-09
  • 2021-06-16
  • 2021-12-31
  • 2021-06-26
相关资源
相似解决方案