EDA探索性数据分析

Data exploration

Check the data

import numpy as np
import pandas as pd
import warnings
warnings.filterwarnings('ignore')
train_df = pd.read_csv('train.csv') 
train_df.head()
 idtargetcomment_textsevere_toxicityobsceneidentity_attackinsultthreatasianatheist...article_idratingfunnywowsadlikesdisagreesexual_explicitidentity_annotator_counttoxicity_annotator_count
0598480.000000This is so cool. It's like, 'would you want yo...0.0000000.00.0000000.000000.0NaNNaN...2006rejected000000.004
1598490.000000Thank you!! This would make my life a lot less...0.0000000.00.0000000.000000.0NaNNaN...2006rejected000000.004
2598520.000000This is such an urgent design problem; kudos t...0.0000000.00.0000000.000000.0NaNNaN...2006rejected000000.004
3598550.000000Is this something I'll be able to install on m...0.0000000.00.0000000.000000.0NaNNaN...2006rejected000000.004
4598560.893617haha you guys are a bunch of losers.0.0212770.00.0212770.872340.00.00.0...2006rejected000100.0447
test_df = pd.read_csv('test.csv') 
test_df.head()
idcomment_text
07000000Jeff Sessions is another one of Trump's Orwell...
17000001I actually inspected the infrastructure on Gra...
27000002No it won't . That's just wishful thinking on ...
37000003Instead of wringing our hands and nibbling the...
47000004how many of you commenters have garbage piled ...

对于测试集应该做的就是提取出类似训练集一样的关键字,并对每一样本进行标注,最后进行训练。 

column_name = train_df.columns.values.tolist() 

['id', 'target', 'comment_text', 'severe_toxicity', 'obscene', 'identity_attack', 'insult', 'threat', 'asian', 'atheist', 'bisexual', 'black', 'buddhist', 'christian', 'female', 'heterosexual', 'hindu', 'homosexual_gay_or_lesbian', 'intellectual_or_learning_disability', 'jewish', 'latino', 'male', 'muslim', 'other_disability', 'other_gender', 'other_race_or_ethnicity', 'other_religion', 'other_sexual_orientation', 'physical_disability', 'psychiatric_or_mental_illness', 'transgender', 'white', 'created_date', 'publication_id', 'parent_id', 'article_id', 'rating', 'funny', 'wow', 'sad', 'likes', 'disagree', 'sexual_explicit', 'identity_annotator_count', 'toxicity_annotator_count']

train_df_1 = train_df.iloc[:,3:23]
train_df_1.head()
severe_toxicityobsceneidentity_attackinsultthreatasianatheistbisexualblackbuddhistchristianfemaleheterosexualhinduhomosexual_gay_or_lesbianintellectual_or_learning_disabilityjewishlatinomalemuslim
00.0000000.00.0000000.000000.0NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
10.0000000.00.0000000.000000.0NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
20.0000000.00.0000000.000000.0NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
30.0000000.00.0000000.000000.0NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
40.0212770.00.0212770.872340.00.00.00.00.00.00.00.00.00.00.00.250.00.00.00.0
train_df_2 = train_df.iloc[:,24:44]
train_df_2.head()
 other_genderother_race_or_ethnicityother_religionother_sexual_orientationphysical_disabilitypsychiatric_or_mental_illnesstransgenderwhitecreated_datepublication_idparent_idarticle_idratingfunnywowsadlikesdisagreesexual_explicitidentity_annotator_count
0NaNNaNNaNNaNNaNNaNNaNNaN2015-09-29 10:50:41.987077+002NaN2006rejected000000.00
1NaNNaNNaNNaNNaNNaNNaNNaN2015-09-29 10:50:42.870083+002NaN2006rejected000000.00
2NaNNaNNaNNaNNaNNaNNaNNaN2015-09-29 10:50:45.222647+002NaN2006rejected000000.00
3NaNNaNNaNNaNNaNNaNNaNNaN2015-09-29 10:50:47.601894+002NaN2006rejected000000.00
40.00.00.00.00.00.00.00.02015-09-29 10:50:48.488476+002NaN2006rejected000100.04
def missing_data(data):
    total = data.isnull().sum()
    percent = (data.isnull().sum()/data.isnull().count()*100)
    tt = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
    types = []
    for col in data.columns:
        dtype = str(data[col].dtype)
        types.append(dtype)
    tt['Types'] = types
    return(np.transpose(tt))
%%time
missing_data(train_df_1)
 severe_toxicityobsceneidentity_attackinsultthreatasianatheistbisexualblackbuddhistchristianfemaleheterosexualhinduhomosexual_gay_or_lesbianintellectual_or_learning_disabilityjewishlatinomalemuslim
Total00000139974413997441399744139974413997441399744139974413997441399744139974413997441399744139974413997441399744
Percent0000077.553677.553677.553677.553677.553677.553677.553677.553677.553677.553677.553677.553677.553677.553677.5536
Typesfloat64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64
%%time
missing_data(train_df_2)

 

 other_genderother_race_or_ethnicityother_religionother_sexual_orientationphysical_disabilitypsychiatric_or_mental_illnesstransgenderwhitecreated_datepublication_idparent_idarticle_idratingfunnywowsadlikesdisagreesexual_explicitidentity_annotator_count
Total1399744139974413997441399744139974413997441399744139974400778646000000000
Percent77.553677.553677.553677.553677.553677.553677.553677.55360043.1413000000000
Typesfloat64float64float64float64float64float64float64float64objectint64float64int64objectint64int64int64int64int64float64int64
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值