Natural Language Processing · free preview

Text Classification with Logistic Regression

Supervised classification setup, hand-built features, the sigmoid and the logit, and vectorized scoring of many documents at once.

1. Text Classification with Logistic Regression

Text Classification with Logistic Regression

2. The sigmoid turns a score into a probability

The sigmoid turns a score into a probability

3. Scoring three reviews in NumPy

Scoring three reviews in NumPy

4. The sigmoid of a logit

Compute σ(−1)\sigma(-1) and round to three decimal places.

5. Scoring a document by weighted sum

A binary sentiment classifier has weights w=[−1,1,0.5]\mathbf{w} = [-1, 1, 0.5] applied to the feature vector x=[3,1,2]\mathbf{x} = [3, 1, 2] and bias b=−0.5b = -0.5. Compute the logit z=w⋅x+bz = \mathbf{w} \cdot \mathbf{x} + b.

6. Reading the decision boundary

A binary classifier outputs y^=0.71\hat{y} = 0.71 as P(y=1∣x)P(y{=}1 \mid x). With the standard threshold, which class does the classifier predict, and which condition explains it?

7. The logit as log odds

Compute the logit of p=0.8p = 0.8, that is ln⁡p1−p\ln \frac{p}{1-p}, and round to three decimal places.

8. Shapes in vectorized scoring

A test set stacks m=6m = 6 documents as rows of X\mathbf{X}, each with n=6n = 6 features. With a weight vector w\mathbf{w} and bias vector b\mathbf{b} (one entry per document), the vectorized form is y^=σ(Xw+b)\hat{\mathbf{y}} = \sigma(\mathbf{X}\mathbf{w} + \mathbf{b}). How many probability values does y^\hat{\mathbf{y}} contain? Answer with the number.

Practice this interactively

Free account · instant grading · spaced review that schedules itself.

Start this course for free