text_plain_output_1.png
from sklearn.model_selection import train_test_split

from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator

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 re

import seaborn  as sns

import string

import tqdm

df = pd.read_csv('/kaggle/input/bbc-fulltext-and-category/bbc-text.csv')
df

df.isna().sum()

plt.yticks(np.arange(0, 550, 50))

x_train, x_test = train_test_split(df, random_state=1, test_size=0.2)
(x_train.shape, x_test.shape)

plt.yticks(np.arange(0, 550, 50))

plt.yticks(np.arange(0, 150, 20))

y_train = x_train['category']
x_train = x_train['text']

y_test = x_test['category']
x_test = x_test['text']

import re
import string
def remove_punch(data):
    cleaned_data = []
    for sentences in data:
        new_sentence = sentences.translate(str.maketrans('', '', string.punctuation))
        new_sentence = re.sub('[\\n\\t]*', '', new_sentence)
        new_sentence = re.sub('  ', '', new_sentence)
        cleaned_data.append(new_sentence)
    return np.array(cleaned_data)

removed_punch_x_train = remove_punch(x_train)
(x_train.shape, removed_punch_x_train.shape)

removed_punch_x_test = remove_punch(x_test)
(x_test.shape, removed_punch_x_test.shape)

import tqdm
def text_vizual(category, data_train):
    text = ''
    for txt in tqdm.tqdm(data_train[y_train == f'{category}']):
        text += txt
    wordcloud_spam = WordCloud(background_color='white').generate(text)
    plt.axis('off')

text_vizual('business', removed_punch_x_train)