File size: 1,377 Bytes
31c93e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from joblib import load
import sys
clf_loaded = load('./QuietML.joblib')  # Load the model


# Defining a function for the Email Spam Detection System
def detect_spam(email_text):
    # Load the trained classifier (clf) here
    # Replace the comment with your code to load the classifier model

    # Make a prediction using the loaded classifier
    prediction = clf_loaded.predict([email_text])
    probabilities = clf_loaded.predict_proba([email_text])
    
    # The probability of being spam (class 1) is usually the second element
    spam_probability = probabilities[0][1] 
    
    # The probability of being ham (class 0) is usually the first element
    ham_probability = probabilities[0][0]


    if prediction == 0:
        output_message = "This is a Ham Email!"
    else:
        output_message = "This is a Spam Email!"
    
    output_message += f"\nProbability (Ham): {ham_probability:.4f}"
    output_message += f"\nProbability (Spam): {spam_probability:.4f}"

    return output_message


# Example of how to use the function
#sample_email = 'hello want a free prize , you gonna have fun with this prize???'
#result = detect_spam(sample_email)
#print(result)
if __name__ == "__main__":
	if len(sys.argv) < 2:
		print("Please provide an email text to classify.")
		sys.exit(1)
    
	email_input = sys.argv[1]
	result = detect_spam(email_input)
	print(result)