FunctionRacerProblemsRace

Spam or Not

Hardscikit-learnPython

texts are messages and labels say which are spam (1) and which are not (0). Build a pipeline that turns each message into TF-IDF weights and classifies them with multinomial naive Bayes, both with default settings. Fit it and return its predictions for new_texts.

Example 1

texts ["win free money now","free prize claim now","meeting at noon today","lunch with the team","claim your free money","team meeting moved","win a prize today","notes from the meeting"]
labels [1,1,0,0,1,0,1,0]
new_texts ["free money prize","team lunch at noon"]
returns [1,0]

The first new message is made of words seen only in spam, the second of words seen only in normal mail.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More scikit-learn problems