Spam or Not
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
8 <= len(texts) <= 40, both labels present1 <= len(new_texts) <= 6- No new message is a close call
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More scikit-learn problems
- Tune Then TestHard
- Hold Some BackBeginner
- Learn Then PredictBeginner
- Names to NumbersBeginner
- Same ScaleBeginner
- Share RightBeginner
- Typical Squared MissBeginner
- What the Model LearnedBeginner