text_plain_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

import numpy as np
import pandas as pd
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('display.max_colwidth', None)
import os
import random
import re
import unicodedata
import gc
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
import torch
import torch.nn as nn
import torch.optim as optim
from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
from datasets import Dataset, DatasetDict

data_path = '/kaggle/input/nlp-getting-started/'

train_df = pd.read_csv(data_path + 'train.csv')
train_df.shape

train_df['target'] = np.float64(train_df.target)

train_df['keyword'].value_counts().head(10).sort_values().plot(kind='barh')

keyword_target = train_df.groupby(['keyword', 'target']).size().unstack(fill_value=0)
keyword_target['disaster_ratio'] = keyword_target[1] / (keyword_target[0] + keyword_target[1])
keyword_target = keyword_target.sort_values(by='disaster_ratio', ascending=False)

# plot the top 10 and bottom 10 keywords by disaster_ratio
fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(10, 10), sharex=True)
keyword_target.head(10)[[0, 1]].plot(kind='barh', ax=axes[0])
keyword_target.tail(10)[[0, 1]].plot(kind='barh', ax=axes[1])
axes[0].set_title('Top 10 keywords by disaster_ratio')
axes[1].set_title('Bottom 10 keywords by disaster_ratio')
plt.show()

train_df['location'].value_counts().head(10).sort_values().plot(kind='barh')

train_df.drop_duplicates(['text', 'target'], inplace=True)

train_df.drop_duplicates(['text'], inplace=True)

sns.boxplot(x='target', y='text_length', data=train_df)
plt.title('Distribution of Tweet Text Lengths by Target')
plt.show()