Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Hello, thank you for your help! The assignment instructions are in the pdf entitled Final.pdf. The assignment creates two short python programs that automatically predict whether an email is spam or...

1 answer below »
Hello, thank you for your help! The assignment instructions are in the pdf entitled Final.pdf. The assignment creates two short python programs that automatically predict whether an email is spam or not spam (given a csv file names spam.csv). The screenshots entiled final_part_one.py and final_part_two.py include code that MUST be included in the resulting programs (part 1 and part 2). The screenshots entitled EXAMPLE 1 and EXAMPLE 2 are my attempts at the code so far; the style of the code should be similar to these examples. My code is not running and I cannot figure out why. Also, I would like a screenshot of the decision tree in WEKA. This is the link for WEKA if needed : https://waikato.github.io/weka-wiki/downloading_weka/. Thank you.
Answered Same Day Nov 27, 2022

Solution

Sanskar answered on Nov 28 2022
29 Votes
SPAM OR HAM
ASSIGNMENT No. – 11461
By- Sanska
Status-Completed , On time
Requirements –
1. Full Python compile setup.
2. Basic knowledge of python.
3. Basic knowledge of read from file.
4. All files must be placed in one folder.
Introduction
To check if any email is spam or not. For this there’s given a file named spam.csv. This program will automatically check length of text , if have spammy words (specified), if have any kind of links and if there are any labels. After checking it will return if the mail is spam or not (ham). In order to check spammy words , all are declared in a list. To increase accuracy of the code user can add more words there (does_have_spammy_words function).
There are total number of 4 files and 1 picture of WEKA diagram :
1. final_part_one.py
2. final_part_two.py
3. spam.csv
4. features.csv
NOTE- In order to run the program/Test the code , delete features.csv file and run final_part_one.py file , The features.csv file will be automatically generated.
WEKA tree Diagram-
According to this WEKA tree code has been designed.
1. first_part_one.py
Comments are available after each function to understand properly .
code-
import csv
# read the span csv file into a list
def read_data_from_file():
    data = []
    with open('spam.csv') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        # slip the first row
        next(csv_reader)
        for row in csv_reader:
            data.append(row)
    return data
# write feature to a file
def write_features_to_file(text_length, does_have_spammy_words, does_have_links, class_label):
    # writing to csv file
    row = [text_length, does_have_spammy_words, does_have_links, class_label]
    with open('features.csv', 'a', newline='', encoding='utf-8') as csvfile:
        # creating a csv writer object
        csvwriter = csv.writer(csvfile)
        # writing the data rows
        csvwriter.writerow(row)
# check if the message has any link inside
def does_has_links(sms_message):
    link_list = ['.com', 'https:
', 'www.', '.net', 'http:
']
    text =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here