06
Jul
2020

Remove Punctuation for Spam Filtering in Python| Tutorial: 2

Remove Punctuation for Spam Filtering in Python| Tutorial: 02. How to Remove Punctuation for Spam Filtering in Python. Welcome to our second tutorial of series for SPAM Detection Tutorials for NLP.

In this tutorial we will discuss that how to How to Remove Punctuation for Spam Filtering in Python?. If you have not seen our previous Tutorial No: 1. We will suggest you please go through it. Click here for tutorial No: 1.

In this series of tutorials you will learn that How to import Dataset in python For Spam Detection Procedure as well as the other aspects in spam detection.

After these tutorials we would be able to create a model that would be enough intelligent to filter spams in SMS and Emails.

# Importing Mandatory Libraries

>>>import  nltk
>>>import  sklearn
>>>import  matplotlib.pyplot as plt|
>>>import  csv
>>>import  numpy as np
>>>import  re
>>>import  pandas as pd
>>>import  matplotlib.pyplot as plt
>>>import  csv
>>>import  wordcloud
>>>import  seaborn
>>>import  string
>>>import  regex

# Importing smsspam Dataset

>>> pd.set_option(‘display.max_colwidth’, 100)
>>> smsspam = pd.read_csv(‘SMSSpamCollection’, sep=“\t”, header=None)
>>> smsspam.columns = [‘label’, ‘msg’]
>>> smsspam.head()

smsspam label heads Remove Punctuation for Spam Filtering in Python| Tutorial: 2
smsspam label heads

Defining remove_punctuation Method

>>> string.punctuation
>>>def remove_punctuation(txt):
txt_nopunct = “”.join([c for c in txt if c not in string.punctuation])
return txt_nopunct

Adding New Column to output Table

>>> smsspam[‘msg_clean’] = smsspam[‘msg’].apply(lambda x: remove_punctuation(x))
>>> smsspam.head()

remove_punctuation output
remove_punctuation output

Download SMS Spam Filtering Dataset

download-button for Remove Punctuation for Spam Filtering dataset

Tutorial No: 1 Import Spam Filtering Dataset in python

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *