A classifier takes an input and predicts a class: a movie review is positive or negative, for example, or a newswire belongs to a topic. The possible categories are classes; the correct category recorded for a training sample is its label. Unlike regression, classification chooses categories rather than predicting a continuous value. section 4.0 section 4.1
Start with movie reviews
To classify sentiment, first turn each review’s words into numeric tensors; one option is a binary vector. A stack of Dense layers with relu activations can process those inputs. For the two classes, end with one sigmoid unit, which outputs a value between 0 and 1, and train with binary_crossentropy. Check performance on data outside the training set: improving training results can conceal overfitting. section 4.1 section 4.1.7
Choose the output layer and loss to match what a sample may belong to:
- Binary: two classes; use one sigmoid output and binary_crossentropy. section 20.6
- Multiclass: one class among several; use softmax with one unit per class. Choose categorical_crossentropy for one-hot targets or sparse_categorical_crossentropy for integer targets. section 20.6
- Multilabel: potentially several classes per sample; use sigmoid outputs, K-hot targets, and binary_crossentropy. Softmax would impose a single-class constraint. section 20.6
Before building a classifier, identify the inputs, the classes, and whether labeled training data exists. A spam detector is binary if it predicts spam versus not spam; adding offensive content as a separate class makes it a three-way task. For images, classification assigns labels to the whole image, whereas segmentation assigns categories to areas and object detection locates objects with bounding boxes. section 6.1.1 section 11.1
A classifier also depends on how its inputs are represented. A change of coordinates can make black and white points separable by a simple rule; devising equally useful transformations by hand for varied handwriting is much harder. section 1.4
preds_a <- model_a |> predict(x_val) #1 preds_b <- model_b |> predict(x_val) preds_c <- model_c |> predict(x_val) preds_d <- model_d |> predict(x_val) final_preds <- 0.25 * (preds_a + preds_b + preds_c + preds_d) #2
This R listing averages four classifiers’ predictions at inference time. Equal averaging is most appropriate when the classifiers perform similarly; otherwise, weights chosen on validation data can provide a stronger baseline. Diversity between classifiers matters because shared biases will survive the average. section 18.1.2






























