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 a binary classification model?
A binary classification model is a type of machine learning model that sorts data into two groups or classes, like deciding if an email is spam or not spam.
Click to reveal answer
beginner
Which activation function is commonly used in the output layer of a binary classification model?
The sigmoid activation function is commonly used because it outputs values between 0 and 1, which can be interpreted as probabilities for the two classes.
Click to reveal answer
beginner
What loss function is typically used to train a binary classification model?
Binary cross-entropy loss is typically used because it measures how well the predicted probabilities match the actual class labels (0 or 1).
Click to reveal answer
beginner
Why do we use accuracy as a metric in binary classification?
Accuracy tells us the percentage of correct predictions out of all predictions, helping us understand how well the model is performing overall.
Click to reveal answer
beginner
What does the output of a binary classification model represent?
The output is a probability score between 0 and 1 that shows how likely the input belongs to the positive class. We usually pick class 1 if the score is above 0.5.
Click to reveal answer
Which activation function is best for the output layer in a binary classification model?
AReLU
BSigmoid
CSoftmax
DTanh
✗ Incorrect
Sigmoid outputs values between 0 and 1, perfect for binary classification probabilities.
What does binary cross-entropy loss measure?
ADifference between predicted probabilities and actual labels
BDistance between data points
CSum of squared errors
DNumber of correct predictions
✗ Incorrect
Binary cross-entropy measures how close predicted probabilities are to the true class labels.
If a model outputs 0.8 for a sample, what class is predicted assuming a 0.5 threshold?
ACannot decide
BClass 0
CClass 1
DClass 2
✗ Incorrect
Since 0.8 is greater than 0.5, the model predicts class 1.
Which metric shows the percentage of correct predictions?
ALoss
BRecall
CPrecision
DAccuracy
✗ Incorrect
Accuracy measures the ratio of correct predictions to total predictions.
What is the typical shape of the output layer in a binary classification model?
AOne neuron with sigmoid activation
BTwo neurons with softmax activation
CMultiple neurons with ReLU activation
DOne neuron with linear activation
✗ Incorrect
Binary classification usually uses one neuron with sigmoid to output a probability.
Explain how a binary classification model works from input to output.
Think about how data flows and how the model decides between two classes.
You got /5 concepts.
Describe the role of the loss function and metric in training a binary classification model.
Consider what guides learning and what tells us how well the model is doing.
You got /4 concepts.
Practice
(1/5)
1. What activation function is commonly used in the output layer of a binary classification model in TensorFlow?
easy
A. Tanh
B. ReLU
C. Softmax
D. Sigmoid
Solution
Step 1: Understand output layer role in binary classification
The output layer must produce a probability between 0 and 1 to represent two classes.
Step 2: Identify suitable activation function
Sigmoid activation compresses output to range [0, 1], perfect for binary decisions.
Final Answer:
Sigmoid -> Option D
Quick Check:
Binary output needs sigmoid = Sigmoid [OK]
Hint: Binary output needs sigmoid activation [OK]
Common Mistakes:
Using softmax for binary output
Using ReLU which outputs unbounded values
Using tanh which outputs between -1 and 1
2. Which of the following is the correct way to compile a binary classification model in TensorFlow?
easy
A. model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
B. model.compile(optimizer='rmsprop', loss='hinge', metrics=['accuracy'])
C. model.compile(optimizer='sgd', loss='mean_squared_error', metrics=['accuracy'])
D. model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
Solution
Step 1: Identify appropriate loss for binary classification
Binary classification requires 'binary_crossentropy' loss to measure error correctly.
Step 2: Check optimizer and metrics
'adam' optimizer and 'accuracy' metric are standard choices for training and evaluation.
Final Answer:
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) -> Option A
Quick Check:
Binary loss = binary_crossentropy [OK]
Hint: Use binary_crossentropy loss for binary classification [OK]
Common Mistakes:
Using categorical_crossentropy for binary tasks
Using mean_squared_error which is for regression
Choosing hinge loss which is for SVMs
3. Given the following TensorFlow model code, what will be the shape of the output layer?
model = tf.keras.Sequential([
tf.keras.layers.Dense(10, activation='relu', input_shape=(5,)),
tf.keras.layers.Dense(1, activation='sigmoid')
])
medium
A. (None, 1)
B. (None, 10)
C. (5, 1)
D. (1,)
Solution
Step 1: Analyze the last layer configuration
The last Dense layer has 1 unit and sigmoid activation, so output shape is (batch_size, 1).
Step 2: Understand batch dimension placeholder
TensorFlow uses None for batch size, so output shape is (None, 1).
Final Answer:
(None, 1) -> Option A
Quick Check:
Output units = 1 means shape = (None, 1) [OK]
Hint: Output shape matches last layer units with batch size None [OK]
Common Mistakes:
Confusing input shape with output shape
Ignoring batch size dimension
Assuming output shape is (1,) without batch
4. You trained a binary classification model but the accuracy stays around 50% after many epochs. Which fix is most likely to improve the model?
medium
A. Change the output activation to softmax
B. Use binary_crossentropy loss instead of categorical_crossentropy
C. Increase the batch size to 1024
D. Remove the activation function from the output layer
Solution
Step 1: Identify the cause of poor accuracy
Using categorical_crossentropy loss with a single sigmoid output causes wrong loss calculation.
Step 2: Apply correct loss function
Switching to binary_crossentropy aligns loss with sigmoid output for binary classification.
Final Answer:
Use binary_crossentropy loss instead of categorical_crossentropy -> Option B
Quick Check:
Loss must match output activation [OK]
Hint: Match loss to output activation for correct training [OK]
5. You want to build a binary classification model to predict if an email is spam or not. Your dataset has 1000 samples with 20 features each. Which model architecture and compile settings are best?
hard
A. Sequential model with one Dense layer (1 unit, sigmoid), compile with binary_crossentropy and adam
B. Sequential model with one Dense layer (20 units, softmax), compile with categorical_crossentropy and sgd
C. Sequential model with two Dense layers (10 units relu, then 1 unit sigmoid), compile with binary_crossentropy and adam
D. Sequential model with three Dense layers (64 relu, 32 relu, 1 tanh), compile with mean_squared_error and rmsprop
Solution
Step 1: Choose model complexity for dataset size
Two layers with relu then sigmoid balance learning capacity and binary output.
Step 2: Select correct loss and optimizer
Binary_crossentropy fits binary tasks; adam optimizer adapts well for small datasets.
Final Answer:
Sequential model with two Dense layers (10 units relu, then 1 unit sigmoid), compile with binary_crossentropy and adam -> Option C
Quick Check:
Two layers + sigmoid + binary_crossentropy = Best practice [OK]