对训练集中的数据做随机抽样,并对抽样出的数据可视化观察分布情况

(1)语料库中56万条数据,分为14个类别

(2)现在训练模型,采样率设定为0.01,即5600条样本

(3)观察用于模型训练数据的分布

 1 def load_data(file_name, sample_ratio=1, n_class=15, names=names, one_hot=True):
 2     '''load data from .csv file'''
 3     csv_file = pd.read_csv(file_name, names=names)
 4     # 对56万条数据做随机采样,获取其中的100分之1
 5     shuffle_csv = csv_file.sample(frac=sample_ratio)
 6     x = pd.Series(shuffle_csv["content"])
 7     y = pd.Series(shuffle_csv["class"])
 8     if one_hot:
 9         y = to_one_hot(y, n_class)
10 
11     # 看一下y值数据的分布
12     y_dist = Counter(y.values)
13     sample = []
14     label = []
15     for i in range(14):
16         label.append(i+1)
17         sample.append(y_dist[i+1])
18     plt.bar(label, sample)
19     plt.show()
20 
21     return x, y

展示:

 

  思考:模型训练的数据不是越多越好吗?何况使用深度学习模型,那作者为什么不不同56万条,而是用5600条训练模型。如果可以达到效果,那么说,对于小容量的数据集,也可以得到一个很好的模型。可以拭目以待。

posted @ 2018-12-25 14:32  今夜无风  阅读(520)  评论(0编辑  收藏  举报