Knowledge Discovery
Midterm

Mock Midterm Exam #2

Closed book · 1 hour · 30 points

Rules

Exercise 1: Binary Strings

Consider binary strings of length 10 (strings made of 0s and 1s).

(a) How many binary strings of length 10 contain exactly 3 ones?

(b) How many binary strings of length 10 contain exactly 3 ones and no two ones are adjacent?

Click to reveal solution

(a) Choose which 3 of the 10 positions hold a one:

\[\binom{10}{3} = \frac{10!}{3!\;7!} = 120\]

(b) We need to place 3 ones among 7 zeros such that no two ones are adjacent. Think of first placing the 7 zeros, which create 8 gaps (before the first zero, between consecutive zeros, and after the last zero):

\[\underset{\uparrow}{\_}\; 0 \;\underset{\uparrow}{\_}\; 0 \;\underset{\uparrow}{\_}\; 0 \;\underset{\uparrow}{\_}\; 0 \;\underset{\uparrow}{\_}\; 0 \;\underset{\uparrow}{\_}\; 0 \;\underset{\uparrow}{\_}\; 0 \;\underset{\uparrow}{\_}\]

Place the 3 ones in 3 distinct gaps (at most one per gap guarantees no adjacency):

\[\binom{8}{3} = 56\]

Exercise 2: Payment Failures

A mobile app observes an average of 2.5 payment failures per day. Assume failures follow a Poisson process.

(a) What is the probability of zero failures tomorrow?

(b) What is the probability of 5 or more failures in the next 2-day period?

Click to reveal solution

(a) With \(\lambda = 2.5\) for one day:

\[P(X = 0) = e^{-2.5} \approx 0.0821\]

(b) Over 2 days, \(\lambda_{2} = 2 \times 2.5 = 5\). We need \(P(X \geq 5) = 1 - P(X \leq 4)\):

\[P(X \leq 4) = e^{-5}\left(1 + 5 + \frac{25}{2} + \frac{125}{6} + \frac{625}{24}\right) = e^{-5}\left(1 + 5 + 12.5 + 20.833 + 26.042\right)\]

\[= e^{-5} \times 65.375 \approx 0.00674 \times 65.375 \approx 0.4405\]

\[P(X \geq 5) = 1 - 0.4405 \approx 0.560\]

There is roughly a 56% chance of seeing 5 or more failures in a 2-day window.

Exercise 3: Fraud Detection Tradeoffs

A fraud detection dataset contains 500 transactions, of which 8 are truly fraudulent. Two models are evaluated:

(a) Compute precision (= TP/(TP+FP)) and recall (= TP/(TP+FN), also called sensitivity) for both models.

(b) The fraud investigation team can review at most 10 flagged cases per day. Which model would you recommend and why?

(c) Now suppose that each missed fraud costs the company €50,000, while each false alarm costs only €200 in wasted review time. Which model would you recommend now?

Click to reveal solution

(a)

Precision Recall
Model A \(\frac{6}{40} = 0.150\) (15%) \(\frac{6}{8} = 0.750\) (75%)
Model B \(\frac{5}{9} \approx 0.556\) (55.6%) \(\frac{5}{8} = 0.625\) (62.5%)

(b) With a capacity of ≤10 reviews/day: Model B. It flags only 9 cases (within the daily budget) with much higher precision (55.6% vs 15%). Model A flags 40 cases — the team physically cannot review them all, meaning many alerts go uninvestigated anyway.

(c) With asymmetric costs (FN = €50,000, FP = €200): Model A. Compare expected costs:

  • Model A: 2 missed frauds × €50,000 + 34 false alarms × €200 = €100,000 + €6,800 = €106,800
  • Model B: 3 missed frauds × €50,000 + 4 false alarms × €200 = €150,000 + €800 = €150,800

When missing fraud is extremely costly, the extra recall of Model A (75% vs 62.5%) saves far more than the cost of its additional false alarms.

Exercise 4: Delivery Time Comparison

A logistics company measures delivery times for two routes:

The routes operate independently.

(a) What is the distribution of \(D = X - Y\)?

(b) What is \(P(X > Y)\), i.e. the probability that Route X takes longer than Route Y?

Click to reveal solution

(a) Since \(X\) and \(Y\) are independent normals, \(D = X - Y\) is also normal:

\[E[D] = E[X] - E[Y] = 10 - 12 = -2\]

\[\text{Var}(D) = \text{Var}(X) + \text{Var}(Y) = 16 + 25 = 41\]

\[D \sim \mathcal{N}(-2,\; 41)\]

(b) \(P(X > Y) = P(D > 0)\). Since \(D \sim \mathcal{N}(-2,\; 41)\), we compute this directly from the CDF of that Gaussian:

\[P(D > 0) = 1 - \Phi_{\mathcal{N}(-2,\,41)}(0) \approx 0.378\]

There is roughly a 37.8% chance that Route X takes longer than Route Y, even though its mean is lower. The high variance on both routes leaves substantial overlap between the two distributions.

Exercise 5: Phishing Filter

A company's email system uses an automated phishing filter. The filter has the following performance characteristics:

(a) What is \(P(\text{phishing} \mid \text{flagged})\)?

(b) A colleague says: "The filter catches 96% of phishing — it must be very reliable." Do you agree? Explain briefly.

Click to reveal solution

(a) Apply Bayes' theorem. First, compute \(P(\text{flagged})\) using the law of total probability:

\[P(\text{flagged}) = P(\text{flagged} \mid \text{phishing}) \cdot P(\text{phishing}) + P(\text{flagged} \mid \text{legit}) \cdot P(\text{legit})\]

\[= 0.96 \times 0.03 + 0.08 \times 0.97 = 0.0288 + 0.0776 = 0.1064\]

Now apply Bayes:

\[P(\text{phishing} \mid \text{flagged}) = \frac{P(\text{flagged} \mid \text{phishing}) \cdot P(\text{phishing})}{P(\text{flagged})} = \frac{0.0288}{0.1064} \approx 0.271\]

About 27.1% of flagged emails are actually phishing.

(b) The colleague is conflating sensitivity with precision. The filter has 96% sensitivity (it catches most phishing), but because phishing is rare (3% base rate), the vast majority of flagged emails are actually legitimate (false positives). Only about 27% of flagged emails are truly phishing — a user reviewing flagged emails would find roughly 3 out of 4 to be false alarms.

Exercise 6: Model Accuracy Across Customers

A machine learning model for invoice classification scored 90 correct out of 100 predictions on an established customer (Customer A). On a new but similar customer (Customer B), a pilot test yields 8 correct out of 10.

(a) Using Customer A's performance as a prior (with a \(\text{Beta}(1,1)\) baseline), write the posterior distribution for Customer B's true accuracy \(\theta\). What is the posterior mean?

(b) A colleague suggests that factually reporting the pilot result as: "80% accuracy." is the best form of reporting. What do you think?

Click to reveal solution

(a) Customer A's 90/100 performance translates to a prior (using a \(\text{Beta}(1,1)\) baseline):

\[\theta \sim \text{Beta}(1 + 90,\; 1 + 10) = \text{Beta}(91, 11)\]

Update with Customer B's pilot data (8 correct, 2 incorrect):

\[\theta \mid \text{data}_B \sim \text{Beta}(91 + 8,\; 11 + 2) = \text{Beta}(99, 13)\]

Posterior mean:

\[E[\theta] = \frac{99}{99 + 13} = \frac{99}{112} \approx 0.884\]

(b) Reporting "80%" ignores 100 observations from Customer A in the same domain. The pilot has only 10 data points — far too few to override what we already know. The posterior properly combines both sources of evidence, estimating accuracy near 88.4%, not 80%. Reporting raw pilot accuracy from a tiny sample is both noisy and wasteful of relevant prior information.

Exercise 7: Dataset Allocation

A research lab has 12 distinct datasets to distribute among three teams: Team A gets 5, Team B gets 4, and Team C gets 3.

How many allocations are possible?

Click to reveal solution

Choose 5 datasets for Team A from the 12, then 4 for Team B from the remaining 7, then the last 3 go to Team C:

\[\binom{12}{5} \times \binom{7}{4} \times \binom{3}{3} = 792 \times 35 \times 1 = 27{,}720\]

Equivalently, this is the multinomial coefficient \(\displaystyle\frac{12!}{5!\;4!\;3!} = 27{,}720\).

Exercise 8: Bugs in Code Review

Let \(X\) be the number of bugs found in a single code review, with the following distribution:

Bugs (\(x\)) 0 1 2 3
Probability 0.50 0.30 0.15 0.05

(a) Compute \(E[X]\) and \(\text{Var}(X)\).

(b) A team conducts 64 independent code reviews. Using the CLT, approximate the probability that the total number of bugs found across all 64 reviews exceeds 55.

Click to reveal solution

(a)

\[E[X] = 0(0.50) + 1(0.30) + 2(0.15) + 3(0.05) = 0 + 0.30 + 0.30 + 0.15 = 0.75\]

\[E[X^2] = 0^2(0.50) + 1^2(0.30) + 2^2(0.15) + 3^2(0.05) = 0 + 0.30 + 0.60 + 0.45 = 1.35\]

\[\text{Var}(X) = E[X^2] - (E[X])^2 = 1.35 - 0.75^2 = 1.35 - 0.5625 = 0.7875\]

(b) Let \(S = X_1 + X_2 + \cdots + X_{64}\). By the CLT:

\[E[S] = 64 \times 0.75 = 48 \qquad \text{Var}(S) = 64 \times 0.7875 = 50.4\]

\[\text{SD}(S) = \sqrt{50.4} \approx 7.10\]

So \(S \approx \mathcal{N}(48,\; 50.4)\). We want \(P(S > 55)\):

\[P(S > 55) = 1 - \Phi_{\mathcal{N}(48,\,50.4)}(55) \approx 0.162\]

About a 16.2% chance of finding more than 55 bugs across 64 reviews.