Datawhale-新闻文本分类-task2-EDA

难受哦

  • 下班回到家,看着提交截至时间不到2小时,认真写,写道11点半,结果电脑突然蓝屏!!!我tm~唉,于是拿了教程的EDA赶紧提交task2. 然后自己补上了一个作业2:查看每个分类最高频率字符
  • 回到家什么都没搞成已经半夜了,难搞哦。又是凌晨睡觉

以下分析结论为引用

数据分析的结论

通过上述分析我们可以得出以下结论:

  • 赛题中每个新闻包含的字符个数平均为1000个,还有一些新闻字符较长;

  • 赛题中新闻类别分布不均匀,数量区间有三个:x>1w, 1w>x>1k, x<1k. 科技类新闻样本量接近4w,星座类新闻样本量不到1k;

  • 赛题总共包括7000-8000个字符;

  • 通过数据分析,我们还可以得出以下结论:

    - 每个新闻平均字符个数较多,可能需要截断;
    
    - 由于类别不均衡,会严重影响模型的精度;
    
import pandas as pd
train_df = pd.read_csv(r'./train_set.csv', sep='\t')

train_df.head()

import matplotlib.pyplot as plt
%pylab inline
train_df['text_len'] = train_df['text'].apply(lambda x: len(x.split(' ')))
print(train_df['text_len'].describe())

_ = plt.hist(train_df['text_len'], bins=200)
plt.xlabel('Text char count')
plt.title("Histogram of char count")

train_df['label'].value_counts().plot(kind='bar')
plt.title('News class count')
plt.xlabel("category")

from collections import Counter
all_lines = ' '.join(list(train_df['text']))
word_count = Counter(all_lines.split(" "))
word_count = sorted(word_count.items(), key=lambda d:d[1], reverse = True)

print(len(word_count))

print(word_count[0])

print(word_count[-1])

from collections import Counter
train_df['text_unique'] = train_df['text'].apply(lambda x: ' '.join(list(set(x.split(' ')))))
all_lines = ' '.join(list(train_df['text_unique']))
word_count = Counter(all_lines.split(" "))
word_count = sorted(word_count.items(), key=lambda d:int(d[1]), reverse = True)

print(word_count[0])

print(word_count[1])

print(word_count[2])

from collections import Counter
train_df['text_unique'] = train_df['text'].apply(lambda x: ' '.join(list(set(x.split(' ')))))
all_lines = ' '.join(list(train_df['text_unique']))
word_count = Counter(all_lines.split(" "))
word_count = sorted(word_count.items(), key=lambda d:int(d[1]), reverse = True)

print(word_count[0])

print(word_count[1])

print(word_count[2])

#统计每类新闻中出现次数对多的字符
label_dic = {'科技': 0, '股票': 1, '体育': 2, '娱乐': 3, '时政': 4, '社会': 5, '教育': 6, '财经': 7, '家居': 8, '游戏': 9, '房产': 10, '时尚': 11, '彩票': 12, '星座': 13}
for (k, v) in label_dic.items():
    tmp = train_df[train_df['label'] == v]
    tmp_all_lines = ' '.join(tmp['text'].tolist())
    tmp_count = Counter(tmp_all_lines.split(' '))
    print('{}新闻类别中最高频率字符是{},出现次数为{}'.format(k, tmp_count[0][0], tmp_count[0][1]))

#统计每类新闻中出现次数对多的字符
label_dic = {'科技': 0, '股票': 1, '体育': 2, '娱乐': 3, '时政': 4, '社会': 5, '教育': 6, '财经': 7, '家居': 8, '游戏': 9, '房产': 10, '时尚': 11, '彩票': 12, '星座': 13}
for (k, v) in label_dic.items():
    tmp = train_df[train_df['label'] == v]
    tmp_all_lines = ' '.join(tmp['text'].tolist())
    tmp_count = Counter(tmp_all_lines.split(' '))
    tmp_count = sorted(tmp_count.items(), key=lambda x: x[1], reverse=True)
    print('{}新闻类别中最高频率字符是{},出现次数为{}'.format(k, str(tmp_count[0][0]), str(tmp_count[0][1])))


posted @ 2020-07-22 23:40  Alexisbusy  阅读(91)  评论(0编辑  收藏  举报