Added initial code.
This commit is contained in:
parent
5808d2f805
commit
1f7a9b0566
22 changed files with 309132 additions and 1 deletions
40
thm/aoc23/day15/complete.py
Normal file
40
thm/aoc23/day15/complete.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python3
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from sklearn.feature_extraction.text import CountVectorizer
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.naive_bayes import MultinomialNB
|
||||
from sklearn.metrics import classification_report
|
||||
|
||||
#Read the email dataset.
|
||||
data = pd.read_csv('emails_dataset.csv')
|
||||
df = pd.DataFrame(data)
|
||||
|
||||
#Convert text to numbers.
|
||||
vectorizer = CountVectorizer()
|
||||
X = vectorizer.fit_transform(df['Message'])
|
||||
|
||||
#Split the dataset for training and testing
|
||||
y = df['Classification']
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
|
||||
|
||||
#Train the model
|
||||
clf = MultinomialNB()
|
||||
clf.fit(X_train, y_train)
|
||||
|
||||
#Evaluate the model's performance
|
||||
y_pred = clf.predict(X_test)
|
||||
print(classification_report(y_test, y_pred))
|
||||
|
||||
#Add a simple test to the model
|
||||
message = vectorizer.transform(["Today's Offer! Claim ur $150 worth of discount vouchers! Text YES to 85023 now! SavaMob, member offers mobile! T Cs 08717898035. $3.00 Sub. 16 . Unsbub reply X"])
|
||||
prediction = clf.predict(message)
|
||||
print("The email is: ", prediction[0])
|
||||
|
||||
#Run the complete test of the emails inside "test_emails.csv"
|
||||
test_data = pd.read_csv("test_emails.csv")
|
||||
|
||||
X_new = vectorizer.transform(test_data['Messages'])
|
||||
new_predictions = clf.predict(X_new)
|
||||
results_df = pd.DataFrame({'Messages': test_data['Messages'], 'Prediction': new_predictions})
|
||||
print(results_df)
|
4452
thm/aoc23/day15/emails_dataset.csv
Normal file
4452
thm/aoc23/day15/emails_dataset.csv
Normal file
File diff suppressed because it is too large
Load diff
37
thm/aoc23/day15/test_emails.csv
Normal file
37
thm/aoc23/day15/test_emails.csv
Normal file
|
@ -0,0 +1,37 @@
|
|||
Messages
|
||||
Reply with your name and address and YOU WILL RECEIVE BY POST a weeks completely free accommodation at various global locations.
|
||||
Kind of. Took it to garage. Centre part of exhaust needs replacing. Part ordered n taking it to be fixed tomo morning.
|
||||
Fighting with the world is easy
|
||||
Why must we sit around and wait for summer days to celebrate. Such a magical sight when the worlds dressed in white. Oooooh let there be snow.
|
||||
Oh
|
||||
ALERT!!!! Get a Chance to Win a 1000$ voucher on your Next Purchase by share the information about the Best Festival company-- the secret code is 'I_HaTe_BesT_FestiVal'
|
||||
i cant talk to you now.i will call when i can.dont keep calling.
|
||||
Today's Offer! Claim ur £150 worth of discount vouchers! Text YES to 85023 now! SavaMob
|
||||
Don't worry though
|
||||
Hey mate. Spoke to the mag people. We‘re on. the is deliver by the end of the month. Deliver on the 24th sept. Talk later.
|
||||
I sent you the prices and do you mean the g
|
||||
Goodmorning
|
||||
Its good
|
||||
Ü takin linear algebra today?
|
||||
Hey so whats the plan this sat?
|
||||
Hey i will be late ah... Meet you at 945+
|
||||
I fetch yun or u fetch?
|
||||
Ok lor. I ned 2 go toa payoh 4 a while 2 return smth u wan 2 send me there or wat?
|
||||
I like dis sweater fr mango but no more my size already so irritating.
|
||||
What makes you most happy?
|
||||
No idea
|
||||
All done
|
||||
Did either of you have any idea's? Do you know of anyplaces doing something?
|
||||
Yes..he is really great..bhaji told kallis best cricketer after sachin in world:).very tough to get out.
|
||||
Hey... Very inconvenient for your sis a not huh?
|
||||
Great! So what attracts you to the brothas?
|
||||
In life when you face choices Just toss a coin not becoz its settle the question But while the coin in the air U will know what your heart is hoping for. Gudni8
|
||||
Haha mayb u're rite... U know me well. Da feeling of being liked by someone is gd lor. U faster go find one then all gals in our group attached liao.
|
||||
Somebody set up a website where you can play hold em using eve online spacebucks
|
||||
I'm really sorry I lit your hair on fire
|
||||
Hello! How's you and how did saturday go? I was just texting to see if you'd decided to do anything tomo. Not that i'm trying to invite myself or anything!
|
||||
And very importantly
|
||||
Ok Chinese food on its way. When I get fat you're paying for my lipo.
|
||||
I'm used to it. I just hope my agents don't drop me since i've only booked a few things this year. This whole me in boston
|
||||
Mode men or have you left.
|
||||
You have to pls make a note of all she.s exposed to. Also find out from her school if anyone else was vomiting. Is there a dog or cat in the house? Let me know later.
|
|
Loading…
Add table
Add a link
Reference in a new issue