@新闻分类大赛赛题分析
本文对天池新闻文本分类比赛进行赛题分析。
1 数据格式
训练集为csv格式文件,使用pandas读取前十行,结果如图。
import pandas as pd
train_df = pd.read_csv(r'train_set.csv', sep='\t')
print(len(train_df))
print(train_df.head(10))
训练集一共20万条数据。
数据集中标签label的对应的关系如下:{‘科技’: 0, ‘股票’: 1, ‘体育’: 2, ‘娱乐’: 3, ‘时政’: 4, ‘社会’: 5, ‘教育’: 6, ‘财经’: 7, ‘家居’: 8, ‘游戏’: 9, ‘房产’: 10, ‘时尚’: 11, ‘彩票’: 12, ‘星座’: 13}
训练文本text做了匿名处理,文字均用数字替代。
2 数据类别分布
利用pandas数据透视,分析每个Label数据量。
table = pd.pivot_table(train_df,index=['label'],aggfunc='count')
print(table)
结果如图:
最多的科技类文本有38918条数据,占据总数据19.5%。而最少的星座类,只有908条数据。
数据不是太均衡,在后续操作中可以适当注意下。
3 文本长度
然后分析每条新闻的长度。
train_df['text_len'] = train_df['text'].str.len()
#增加一列"text_len",计算text长度
col_mean = train_df[["text_len"]].mean()
col_mean["label"]="mean"
#增加一行,计算长度均值
col_max = train_df[["text_len"]].max()
col_max["label"]="max"
#增加一行,计算长度最大值
col_min = train_df[["text_len"]].min()
col_min["label"]="min"
#增加一行,计算长度最小值
train_df=train_df.append(col_mean,ignore_index=True)
train_df=train_df.append(col_max,ignore_index=True)
train_df=train_df.append(col_min,ignore_index=True)
print(train_df.tail(6))
#输出最后6行
结果如图
可以看出长度平均在4400左右,最长283530,最短为9。初步判断为长文本分类。
4 思路
鉴于数据匿名处理,一方面可以视为one-hot编码,另外一方面不太好直接使用现成的预训练模型编码。
本次是第一次参加比赛,想先用机器学习的方法,比如朴素贝叶斯、XGBoost等方法实现。
群里面提到这类数据用text GCN比较好,后期可以尝试。