0
0
ML Pythonml~20 mins

Multi-label classification in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-label Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Multi-label Classification

Which statement best describes multi-label classification?

AEach instance is assigned exactly one label from multiple classes.
BEach instance can be assigned multiple labels simultaneously.
CIt is a regression problem predicting continuous values.
DLabels are predicted sequentially, one after another.
Attempts:
2 left
💡 Hint

Think about whether an example can belong to more than one category at the same time.

Model Choice
intermediate
2:00remaining
Choosing a Model for Multi-label Classification

You want to build a multi-label classifier. Which model architecture is most suitable?

AA neural network with multiple output neurons using sigmoid activation.
BA decision tree that outputs one label per instance.
CA linear regression model predicting continuous values.
DA neural network with a single output neuron using softmax activation.
Attempts:
2 left
💡 Hint

Consider how the output layer should handle multiple labels independently.

Metrics
advanced
2:00remaining
Evaluating Multi-label Classification Performance

Which metric is best suited to evaluate a multi-label classification model?

AMean Squared Error between predicted and true labels.
BAccuracy calculated as (correct predictions / total samples).
CHamming Loss measuring the fraction of wrong labels to total labels.
DR-squared score measuring variance explained by the model.
Attempts:
2 left
💡 Hint

Think about a metric that counts label-wise errors in multi-label settings.

Predict Output
advanced
2:00remaining
Output of Multi-label Prediction Code

What is the output of the following Python code snippet?

ML Python
import numpy as np
from sklearn.preprocessing import MultiLabelBinarizer

labels = [['cat', 'dog'], ['dog'], ['mouse', 'cat'], []]
mlb = MultiLabelBinarizer(classes=['cat', 'dog', 'mouse'])
encoded = mlb.fit_transform(labels)
print(encoded.tolist())
A[[1, 1, 1], [0, 1, 0], [1, 0, 1], [0, 0, 0]]
B[[1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 0, 0]]
C[[0, 1, 1], [1, 0, 0], [0, 1, 1], [0, 0, 0]]
D[[1, 1, 0], [0, 1, 0], [1, 0, 1], [0, 0, 0]]
Attempts:
2 left
💡 Hint

Check the order of classes and how MultiLabelBinarizer encodes labels.

🔧 Debug
expert
3:00remaining
Debugging Multi-label Classification Training Issue

Given this training code snippet for a multi-label classifier, what is the main cause of the error?

import torch
import torch.nn as nn

model = nn.Sequential(
    nn.Linear(10, 3),
    nn.Softmax(dim=1)
)

criterion = nn.BCEWithLogitsLoss()
inputs = torch.randn(5, 10)
targets = torch.randint(0, 2, (5, 3)).float()
outputs = model(inputs)
loss = criterion(outputs, targets)
AUsing Softmax activation before BCEWithLogitsLoss causes incorrect input range.
BTargets should be integers, not floats, for BCEWithLogitsLoss.
CThe input tensor shape does not match the model output shape.
DBCEWithLogitsLoss requires outputs to be probabilities between 0 and 1.
Attempts:
2 left
💡 Hint

Consider what BCEWithLogitsLoss expects as input and what Softmax outputs.