Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. #Extract Emails
  2. tech = extract_message("C:\Users\Cody\Documents\Emails\tech.html")
  3. gary = extract_message("C:\Users\Cody\Documents\Emails\gary.html")
  4. gary2 = extract_message("C:\Users\Cody\Documents\Emails\gary2.html")
  5. jesus = extract_message("C:\Users\Cody\Documents\Emails\Jesus.html")
  6. jesus2 = extract_message("C:\Users\Cody\Documents\Emails\jesus2.html")
  7. hockey = extract_message("C:\Users\Cody\Documents\Emails\hockey.html")
  8. hockey2 = extract_message("C:\Users\Cody\Documents\Emails\hockey2.html")
  9. shop = extract_message("C:\Users\Cody\Documents\Emails\shop.html")
  10.  
  11. #Build dictionary of features
  12. count_vect = CountVectorizer()
  13. x_train_counts = count_vect.fit_transform(news.data)
  14.  
  15. #Downscaling
  16. tfidf_transformer = TfidfTransformer()
  17. x_train_tfidf = tfidf_transformer.fit_transform(x_train_counts)
  18. tf_transformer = TfidfTransformer(use_idf=False).fit(x_train_counts)
  19. x_train_tf = tf_transformer.transform(x_train_counts)
  20.  
  21. #Train classifier
  22. clf = MultinomialNB().fit(x_train_tfidf, news.target)
  23.  
  24. #List of the extracted emails
  25. docs_new = [gary, gary2, jesus, jesus2, shop, tech, hockey, hockey2]
  26.  
  27. #Extract feautures from emails
  28. x_new_counts = count_vect.transform(docs_new)
  29. x_new_tfidf = tfidf_transformer.transform(x_new_counts)
  30.  
  31. #Predict the categories for each email
  32. predicted = clf.predict(x_new_tfidf)
  33.  
  34. #Store Files in a category
  35. hockey_emails = []
  36. computer_emails = []
  37. politics_emails = []
  38. tech_emails = []
  39. religion_emails = []
  40. forsale_emails = []
  41.  
  42. #Print out results and store each email in the appropritate category list
  43. for doc, category in zip(docs_new, predicted):
  44. print('%r ---> %s' % (doc, news.target_names[category]))
  45. if(news.target_names[category] == 'comp.sys.ibm.pc.hardware'):
  46. computer_emails.append(doc)
  47. if(news.target_names[category] == 'rec.sport.hockey'):
  48. hockey_emails.append(doc)
  49. if(news.target_names[category] == 'talk.politics.misc'):
  50. politics_emails.append(doc)
  51. if(news.target_names[category] == 'soc.religion.christian'):
  52. religion_emails.append(doc)
  53. if(news.target_names[category] == 'misc.forsale'):
  54. forsale_emails.append(doc)
  55. if(news.target_names[category] == 'comp.sys.ibm.pc.hardware'):
  56. computer_emails.append(doc)
  57.  
  58. print(hockey_emails)
  59.  
  60. output: ['hockey', 'hockey2']
  61.  
  62. output: ['View View online click here Hi Thanks for signing up as a EA SPORTS NHL insider You ll now receive all of the latest and greatest news and info at this e mail address as you ve requested EA com If you need technical assistance please contact EA Help Privacy Policy Our Certified Online Privacy Policy gives you confidence whenever you play EA games To view our complete Privacy and Cookie Policy go to privacy ea com or write to Privacy Policy Administrator Electronic Arts Inc Redwood Shores Parkway Redwood City CA Electronic Arts Inc All Rights Reserved Privacy Policy User Agreement Legal ActionsMark as UnreadMark as ReadMark as SpamStarClear StarArchive Previous Next ', 'View News From The Hockey Writers The Editor s Choice stories from The Hockey Writers View this email in your browser edition Recap Stars Steamroll Predators By Matt Pryor on Dec am As the old Mary Chapin Carpenter song goes Sometimes you re the windshield Sometimes you re the bug It hasn t happened very often this season but the Dallas Stars had a windshield Continue Reading A Review of Years in Blue and White Damien Cox One on One By Anthony Fusco on Dec pm The Toronto Maple Leafs are one of the most storied and iconic franchises in the entire National Hockey League They have a century of history that spans all the way back to the early s When you have an Continue Reading Bruins Will Not Miss Beleskey By Kyle Benson on Dec am On Monday it was announced that Matt Beleskey will miss the next six weeks due to a knee injury he sustained over the weekend in a game against the Buffalo Sabres Six weeks is a long stint to be without a potential top Continue Reading Recent Articles Galchenyuk Injury Costly for CanadiensFacing Off Picking Team Canada for World JuniorsAre Johnson s Nomadic Days Over Share Tweet Forward Latest News Prospects Anaheim Ducks Arizona Coyotes Boston Bruins Buffalo Sabres Calgary Flames Carolina Hurricanes Chicago Blackhawks Colorado Avalanche Columbus Blue Jackets Dallas Stars Detroit Red Wings Edmonton Oilers Florida Panthers Los Angeles Kings Minnesota Wild Montreal Canadiens Nashville Predators New Jersey Devils New York Islanders New York Rangers Philadelphia Flyers Pittsburgh Penguins Ottawa Senators San Jose Sharks St Louis Blues Tampa Bay Lightning Toronto Maple Leafs Vancouver Canucks Washington Capitals Winnipeg Jets Copyright The Hockey Writers All rights reserved You are receiving this email because you opted in at The Hockey Writers or one of our Network Sites Our mailing address is The Hockey Writers Victoria Ave St Lambert QC J R R CanadaAdd us to your address book unsubscribe from this list update subscription preferences ActionsMark as UnreadMark as ReadMark as SpamStarClear StarArchive Previous Next ']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement