image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

sarcasm_df = pd.read_csv('../input/sarcasm/train-balanced-sarcasm.csv')

sarcasm_df.dropna(subset=['comment'], inplace=True)
sarcasm_df['comment'] = sarcasm_df['comment'].str.lower()
sarcasm_df['comment'] = sarcasm_df['comment'].str.replace('[^\\w\\s]', '')

sarcasm_df.created_utc = pd.to_datetime(sarcasm_df.created_utc)

plt.figure(figsize=(5,5))
ax = sns.countplot(x='label',  data= sarcasm_df)
ax.set(title = "Distribution of Classes", xlabel="Sarcasm Status", ylabel = "Total Count")
total = float(len(sarcasm_df ))
for p in ax.patches:
    height = p.get_height()
    ax.text(p.get_x()+p.get_width()/2.,
            height + 3,
            '{:1.1f}%'.format((height/total)*100),
            ha="center") 
plt.show()

sns.despine(offset=10, trim=True)

sns.despine(offset=10, trim=True)

sarcasm_df['log_comment'] = sarcasm_df['comment'].apply(lambda text: np.log1p(len(text)))
sarcasm_df[sarcasm_df['label'] == 1]['log_comment'].hist(alpha=0.6, label='Sarcastic', color='blue')
sarcasm_df[sarcasm_df['label'] == 0]['log_comment'].hist(alpha=0.6, label='Non-Sarcastic', color='red')
plt.legend()
plt.title('Natural Log Length of Comments')
plt.show()