Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the purpose of a loss function in machine learning?
A loss function measures how well a model's predictions match the actual data. It tells the model how wrong it is so it can learn and improve.
Click to reveal answer
beginner
Explain Mean Squared Error (MSE) loss function.
MSE calculates the average of the squares of the differences between predicted and actual values. It punishes bigger errors more, helping models learn precise predictions.
Click to reveal answer
beginner
What type of problems is cross-entropy loss used for?
Cross-entropy loss is used for classification problems. It measures how close the predicted probabilities are to the actual class labels.
Click to reveal answer
intermediate
How does cross-entropy loss handle predictions that are very wrong?
Cross-entropy loss gives a high penalty when the predicted probability for the true class is very low, encouraging the model to predict probabilities closer to the true labels.
Click to reveal answer
beginner
Show a simple TensorFlow code snippet to compute MSE loss.
A. Missing parentheses after CategoricalCrossentropy
B. Wrong optimizer name
C. Metrics should be 'loss' not 'accuracy'
D. Loss function should be a string, not an object
Solution
Step 1: Check loss function usage in compile
Loss functions must be called as objects, so parentheses are needed.
Step 2: Identify missing parentheses
tf.keras.losses.CategoricalCrossentropy is a class; missing () means passing the class, not an instance.
Final Answer:
Missing parentheses after CategoricalCrossentropy -> Option A
Quick Check:
Loss function needs () to create instance [OK]
Hint: Always add () when passing loss function classes [OK]
Common Mistakes:
Forgetting parentheses on loss functions
Confusing optimizer names
Using wrong metric names
5. You have a multi-class classification problem with 4 classes. Which loss function and output layer activation should you use in TensorFlow for best results?
hard
A. Use Mean Squared Error loss with sigmoid activation
B. Use Categorical Cross-Entropy loss with softmax activation
C. Use Binary Cross-Entropy loss with softmax activation
D. Use Hinge loss with linear activation
Solution
Step 1: Identify problem type and output requirements
Multi-class classification with 4 classes requires probabilities summing to 1.
Step 2: Match loss and activation functions
Softmax activation outputs probabilities for each class; categorical cross-entropy measures loss for multi-class.
Final Answer:
Use Categorical Cross-Entropy loss with softmax activation -> Option B