Course materials · Introduction to Machine Learning

Logistic Regression

English translation

After obtaining probabilities, use a Threshold to decide whether to prioritize reducing missed detections or false alarms.

Before practice

01 Must a probability of 0.6 always be classified as positive?

Description

The decision criterion can change depending on the goals for false alarms and missed detections.

02 Is Accuracy alone sufficient when class counts are imbalanced?

Description

Accuracy can be high from predicting only the majority class, so also examine missed detections and false alarms for each class.

Practice

Preview practice notebookDownload practice notebook

1. Logits, Probabilities, and Decisions

Starting conditions

logit=[−2−0.500.52]\mathrm{logit}=\begin{bmatrix}-2&-0.5&0&0.5&2\end{bmatrix}, Label=[00111]\mathrm{Label}=\begin{bmatrix}0&0&1&1&1\end{bmatrix}.

Procedure

  1. Calculate probabilities with Sigmoid and record decisions at Threshold=.5.
  2. Compare TP, FP, FN, TN, and Accuracy at Threshold=.3,.5,.7.

Results to retain

Items to record and points to check
Threshold
TP
FP
FN
TN
Accuracy

Points to check

  • Did you avoid treating probabilities and final labels as the same values?

2. Choosing Which Errors to Reduce

Starting conditions

Choose one of the three Thresholds for a sensor alarm scenario that prioritizes reducing missed detections (FN).

Procedure

  1. Reuse the TP, FP, FN, TN, and Accuracy table for each threshold 0.3,0.5,0.70.3,0.5,0.7 from the previous activity. Use the same logits and labels.
  2. Find the Threshold candidates with the fewest FNs. If candidates tie, compare their FPs, select one value, and record the FN and FP counts supporting your choice.
  3. Compare the decisions from your selected value and Threshold 0.5 for each sample, and explain which samples have different alarms.

Results to retain

Items to record and points to check
Threshold
FN
FP
Selected value and reasoning

Points to check

  • If candidates tied, did you record the reason for your choice?

3. Checking Other Inputs

Starting conditions

Compare a model that always predicts 0 on 100 synthetic Labels, 10% of which are Class 1.

Procedure

  1. Create a Label array with 10 Class 1 samples and 90 Class 0 samples, and a prediction array filled with 0.
  2. Before running the code, calculate TP, FP, FN, TN, and Accuracy. Calculate the same values in code and compare them. Also record the number of missed Class 1 samples.
  3. Even if accuracy is high, can you conclude that the model reduces missed detections? Explain using your recorded FN.

Results to retain

Items to record and points to check
TP, FP, FN, TN before running
Actual TP, FP, FN, and TN
Accuracy
Missed Class 1 count and interpretation

Points to check

  • Did you distinguish overall Accuracy from the number of missed Class 1 samples?