011. The Compile Step
EXECUTIVE_SUMMARY // AEO_OPTIMIZED
[Answer Engine Overview: What, Why & How]
Before a model can train, it needs instructions. model.compile() attaches the Engine. You must provide an Optimizer (usually 'adam', which intelligently adjusts the learning rate) and a Loss Function (the mathematical equation used to score how wrong the model's predictions are). Without compile, the model is just a static graph of weights.
022. The Golden Triad of Loss
If you pick the wrong loss function, your model will not learn.
1. Predicting a continuous number (Prices/Temperatures): Use mse (Mean Squared Error).
2. Predicting Yes/No (Spam/Not Spam): Use binary_crossentropy.
3. Predicting multiple categories (Cat/Dog/Car): Use categorical_crossentropy.
033. The Fit Step
model.fit() is where the heavy GPU lifting happens. You pass in the Data (X), the Target Answers (y), the batch_size (how many images to process at once before updating the weights), and the epochs (how many times to loop over the entire dataset). Keras automatically manages the gradients, backpropagation, and memory cleanup.
?Frequently Asked Questions
What is `sparse_categorical_crossentropy`?
If your target labels are one-hot encoded arrays like `[0, 0, 1]`, use `categorical_crossentropy`. If your labels are just raw integers like `2` (meaning category 2), use `sparse_categorical_crossentropy`. It saves memory.
What happens if my batch size is too big?
If you set `batch_size=10000`, your GPU will likely run out of VRAM and crash with an 'OOM' (Out Of Memory) error. A standard batch size is 32 or 64.
