Natural language processing: mystery friend

Welcome to the Get Help category!
Hi,

I’ve been trying to solve the NLP task for the mystery friend challenge. I would like to know if it’s Henson. I want to understand why code academy isn’t offering solutions to more complex exercises like this one as we are left hanging with no idea whether our work is correct.

I printed the output of the exercise and got [2]. Does that suggest that it’s the writer labelled as 2?

Please help out

Could you link the project?

Thank you for getting back this fast.

Link:
https://www.codecademy.com/paths/data-science/tracks/dscp-natural-language-processing/modules/dscp-bag-of-words/projects/bag-of-words-mystery-friend

from goldman_emma_raw import goldman_docs from henson_matthew_raw import henson_docs from wu_tingfang_raw import wu_docs # import sklearn modules here: #1. Import CountVectorizer and Naives Bayes MultinomialNB from sklearn.feature_extraction.text import CountVectorizer from sklearn.naive_bayes import MultinomialNB # Setting up the combined list of friends' writing samples friends_docs = goldman_docs + henson_docs + wu_docs # Setting up labels for your three friends friends_labels = [1] * 154 + [2] * 141 + [3] * 166 # Print out a document from each friend: # print(goldman_docs) # print(henson_docs) # print(wu_docs) mystery_postcard = """ My friend, From the 10th of July to the 13th, a fierce storm raged, clouds of freeing spray broke over the ship, incasing her in a coat of icy mail, and the tempest forced all of the ice out of the lower end of the channel and beyond as far as the eye could see, but the _Roosevelt_ still remained surrounded by ice. Hope to see you soon. """ # Create bow_vectorizer: bow_vectorizer = CountVectorizer() # Define friends_vectors: friends_vectors = bow_vectorizer.fit_transform(friends_docs) # Define mystery_vector: mystery_vector = bow_vectorizer.transform([mystery_postcard]) print(henson_docs[0]) # Define friends_classifier: friends_classifier = MultinomialNB() # Train the classifier: friends_classifier.fit(friends_vectors,friends_labels) print(friends_classifier.predict(mystery_vector)) # Change predictions: predictions = ["Henson"] mystery_friend = predictions[0] if predictions[0] else "someone else" # Uncomment the print statement: print("The postcard was from {}!".format(mystery_friend))

I believe the ‘mystery postcard’ is just a quote from a piece of work available from one of those authors at the ProjectGutenberg site (linked in that project) so you can just hunt it down. I’m pretty sure you have the correct answer anyway.

Thank you for that. I appreciate the lengths you have to help me get a definite answer. :slightly_smiling_face: I’ll try to make sure that I’ve got it right as you mentioned their work should be on ProjectGutenberg.

All the best stay safe!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.