Challenge - 5 Problems
Logistic Regression Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateUnderstanding the output of logistic regression
What does the output of a logistic regression model represent?
Attempts:
2 left
💡 Hint
Think about what logistic regression outputs before applying a threshold.
✗ Incorrect
Logistic regression outputs a probability value between 0 and 1 indicating the likelihood that the input belongs to the positive class. The final class label is obtained by applying a threshold (usually 0.5) to this probability.
❓ Predict Output
intermediateOutput of logistic regression prediction code
What is the output of this Python code using scikit-learn's LogisticRegression?
ML Python
from sklearn.linear_model import LogisticRegression import numpy as np X = np.array([[1, 2], [2, 3], [3, 4], [4, 5]]) y = np.array([0, 0, 1, 1]) model = LogisticRegression() model.fit(X, y) preds = model.predict(np.array([[1, 2], [3, 5]])) print(preds.tolist())
Attempts:
2 left
💡 Hint
The model learns to separate classes based on the training data pattern.
✗ Incorrect
The model predicts class 0 for input [1, 2] because it is similar to training samples labeled 0, and class 1 for [3, 5] because it is closer to samples labeled 1.
❓ Hyperparameter
advancedChoosing the regularization parameter in logistic regression
Which effect does increasing the regularization strength (C parameter) in scikit-learn's LogisticRegression have?
Attempts:
2 left
💡 Hint
Remember that in scikit-learn, C is the inverse of regularization strength.
✗ Incorrect
In scikit-learn, a higher C means less regularization, so the model can fit the training data more closely. Lower C means stronger regularization, which simplifies the model.
❓ Metrics
advancedInterpreting logistic regression evaluation metrics
If a logistic regression model has a high accuracy but low recall on the positive class, what does this imply?
Attempts:
2 left
💡 Hint
Recall measures how many actual positives are found by the model.
✗ Incorrect
Low recall means many positive cases are missed (false negatives). High accuracy can still occur if negatives are correctly classified, especially if negatives are the majority.
🔧 Debug
expertIdentifying the cause of poor logistic regression convergence
Given this code snippet, why might the logistic regression model fail to converge?
ML Python
from sklearn.linear_model import LogisticRegression import numpy as np X = np.random.rand(1000, 50) y = np.random.randint(0, 2, 1000) model = LogisticRegression(max_iter=10) model.fit(X, y)
Attempts:
2 left
💡 Hint
Consider the number of iterations allowed for training.
✗ Incorrect
The default logistic regression solver may need more iterations to converge on high-dimensional data. Setting max_iter too low (10) often causes convergence warnings or failure.
