Model Pipeline - Logistic regression for text
This pipeline shows how logistic regression can classify text messages as positive or negative by turning words into numbers and learning from examples.
Jump into concepts and practice - no test required
This pipeline shows how logistic regression can classify text messages as positive or negative by turning words into numbers and learning from examples.
Loss
0.7 |****
0.6 |***
0.5 |**
0.4 |*
0.3 |
1 2 3 4 5 Epochs| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 0.65 | 0.60 | Model starts learning, loss high, accuracy low |
| 2 | 0.50 | 0.75 | Loss decreases, accuracy improves |
| 3 | 0.40 | 0.82 | Model learns important word patterns |
| 4 | 0.35 | 0.85 | Loss continues to drop, accuracy rises |
| 5 | 0.32 | 0.87 | Training converges with good accuracy |
from sklearn.feature_extraction.text import CountVectorizer from sklearn.linear_model import LogisticRegression texts = ['good movie', 'bad movie'] labels = [1, 0] vectorizer = CountVectorizer() X = vectorizer.fit_transform(texts) model = LogisticRegression() model.fit(X, labels) pred = model.predict(vectorizer.transform(['good movie'])) print(pred)
from sklearn.linear_model import LogisticRegression from sklearn.feature_extraction.text import CountVectorizer texts = ['happy', 'sad'] labels = [1, 0] vectorizer = CountVectorizer() X = vectorizer.fit_transform(texts) model = LogisticRegression() model.fit(texts, labels)