机器学习训练营——机器学习爱好者的自由交流空间(入群联系qq:2279055353)
案例介绍
一项由谷歌发起的研究,使用机器学习技术识别在线谈话里的有害评论。这里的“有害评论”,是指任何粗鲁的(rude
)、无礼的(disrespectful
), 或者其它导致某人终止讨论的言谈。该案例将构建分类模型,识别有害评论,并且减少不需要的偏差。例如,一个特定的名字经常与有害评论联系,一些模型可能把出现在无害评论里的同名的评论错误地分在有害评论里。
数据描述
在案例数据集里,每一条评论文本在comment_text
列。训练集的每一条评论有一个toxicity
标签(target
), 开发的模型将预测检验集里的target
. 所有其它属性是给定评论的属性比例值。为了便于评价模型,在检验集里,target>0.5
的样本被标记为阳性类(toxic
).
加载包
import gc
import os
import warnings
import operator
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from tqdm import tqdm_notebook
from wordcloud import WordCloud, STOPWORDS
import gensim
from gensim.utils import simple_preprocess
from gensim.parsing.preprocessing import STOPWORDS
from nltk.stem import WordNetLemmatizer, SnowballStemmer
from nltk.stem.porter import *
import nltk
from gensim import corpora, models
import pyLDAvis
import pyLDAvis.gensim
from keras.preprocessing.text import Tokenizer
pyLDAvis.enable_notebook()
np.random.seed(2018)
warnings.filterwarnings('ignore')
加载数据
JIGSAW_PATH = "../input/jigsaw-unintended-bias-in-toxicity-classification/"
train = pd.read_csv(os.path.join(JIGSAW_PATH,'train.csv'), index_col='id')
test = pd.read_csv(os.path.join(JIGSAW_PATH,'test.csv'), index_col='id')
显示train
, test
的前5行。
train.head(), test.head()