Knowledge Discovery
Midterm

Mock Midterm Exam — Solutions

Closed book · 1 hour · 30 points

Rules

Exercise 1: Course Enrollment

Among students at the university:

(a) What is \(P(\text{KM} \cap \text{AID})\)?

Click to reveal solution

We know \(P(\text{AID} \mid \text{KM}) = 0.28\) and \(P(\text{KM}) = 0.35\).

By the definition of conditional probability:

\[P(\text{KM} \cap \text{AID}) = P(\text{AID} \mid \text{KM}) \cdot P(\text{KM}) = 0.28 \times 0.35 = 0.098\]


(b) What is \(P(\text{KM} \mid \text{AID})\)?

Click to reveal solution

Using Bayes' theorem:

\[P(\text{KM} \mid \text{AID}) = \frac{P(\text{AID} \mid \text{KM}) \cdot P(\text{KM})}{P(\text{AID})} = \frac{0.28 \times 0.35}{0.40} = \frac{0.098}{0.40} = 0.245\]

Exercise 2: DNA Base Pairs

A DNA sequence called a "turn" consists of 11 consecutive base pairs. Each base pair can be one of four distinct nucleotides: A, T, G, or C.

How many distinct DNA turns are possible?

Click to reveal solution

Each of the 11 positions can independently be one of 4 nucleotides. By the multiplication rule:

\[4^{11} = 4{,}194{,}304\]

Exercise 3: Project Groups

A professor must divide 99 students into 33 project groups of 3 students each. In how many ways can this be done? (Neither the order of groups nor the order of students within each group matters.)

Click to reveal solution

First, choose 3 students out of 99 for the first group, then 3 out of 96 for the second, and so on:

\[\binom{99}{3}\binom{96}{3}\binom{93}{3}\cdots\binom{3}{3} = \frac{99!}{(3!)^{33}}\]

However, this treats the 33 groups as distinguishable (first group chosen, second group chosen, etc.). Since the order of the groups does not matter, we divide by \(33!\):

\[\frac{99!}{(3!)^{33} \cdot 33!}\]

Exercise 4: Investment Portfolio

An investor has $20 million to allocate among 4 companies in units of $1 million. The minimum investments are $1 million for Company 1, $2 million for Company 2, $3 million for Company 3, and $4 million for Company 4.

(a) In how many ways can the investor allocate the money if an investment must be made in each company?

Click to reveal solution

First, satisfy the minimums: give $1M to C1, $2M to C2, $3M to C3, $4M to C4. That uses \(1+2+3+4 = 10\) million, leaving \(20 - 10 = 10\) million to distribute freely among 4 companies.

This is a stars-and-bars problem: distribute 10 identical units among 4 bins (each bin \(\geq 0\)):

\[\binom{10 + 4 - 1}{4 - 1} = \binom{13}{3} = 286\]


(b) In how many ways if investments must be made in at least 3 of the 4 companies?

Click to reveal solution

We need to count allocations where at least 3 companies receive their minimum (or more). We split into two cases:

Case 1: All 4 companies receive investment (exactly the answer from part (a)):

\[\binom{13}{3} = 286\]

Case 2: Exactly 3 companies receive investment (one company gets $0). We skip each company in turn and distribute $20M among the remaining 3, respecting their minimums:

  • Skip C1 (min $1): remaining minimums \(2+3+4=9\), leftover \(20-9=11\) among 3 bins → \(\binom{11+2}{2} = \binom{13}{2} = 78\)
  • Skip C2 (min $2): remaining minimums \(1+3+4=8\), leftover \(20-8=12\) among 3 bins → \(\binom{12+2}{2} = \binom{14}{2} = 91\)
  • Skip C3 (min $3): remaining minimums \(1+2+4=7\), leftover \(20-7=13\) among 3 bins → \(\binom{13+2}{2} = \binom{15}{2} = 105\)
  • Skip C4 (min $4): remaining minimums \(1+2+3=6\), leftover \(20-6=14\) among 3 bins → \(\binom{14+2}{2} = \binom{16}{2} = 120\)

Case 2 total: \(78 + 91 + 105 + 120 = 394\)

Final answer:

\[286 + 394 = 680\]

Exercise 5: Software Bug

A non-deterministic bug in software causes catastrophic failures. During testing over 400 hours, the bug occurred exactly twice. Assume occurrences follow a Poisson process.

(a) A user runs a 3-hour task. What is the probability the bug manifests at least once?

Click to reveal solution

First, estimate the rate parameter. Over 400 hours we observed 2 events:

\[\lambda = \frac{2}{400} = 0.005 \text{ events/hour}\]

For a 3-hour window, the expected number of events is:

\[\mu = \lambda \cdot t = 0.005 \times 3 = 0.015\]

In a Poisson process, \(P(X = k) = \frac{\mu^k e^{-\mu}}{k!}\). We want at least one occurrence:

\[P(X \geq 1) = 1 - P(X = 0) = 1 - e^{-0.015} \approx 1 - 0.9851 = 0.0149\]

About a 1.5% chance the bug strikes during a 3-hour task.

Exercise 6: AI Model Effectiveness

A data scientist deploys an AI model for customer churn prediction in online game sales. The model's quality for Customer A is 85 correct predictions out of 100. In a pilot test on a new customer, Customer B, in the same domain of online game sales, the model correctly predicts 6 outcomes and incorrectly predicts 4.

(a) How would you report your accuracy estimate for Customer B?

Click to reveal solution

Since Customer B is in the same domain as Customer A, we can use the Customer A results as an informative prior. The 85/100 performance on Customer A translates to a prior:

\[\theta \sim \text{Beta}(85, 15)\]

Now we update with Customer B's data (6 successes, 4 failures):

\[\theta \mid \text{data}_B \sim \text{Beta}(85 + 6,\; 15 + 4) = \text{Beta}(91, 19)\]

The posterior mean is:

\[\mathbb{E}[\theta] = \frac{91}{91 + 19} = \frac{91}{110} \approx 0.827\]

So rather than reporting the naive 6/10 = 60% from Customer B's small test alone, we report a posterior estimate of about 82.7%. The strong prior from the same domain pulls the estimate up, reflecting that 10 data points are too few to override what we already know about the model's performance in online game sales.

We should also report uncertainty. A 95% credible interval is the interval \([L, U]\) such that 95% of the posterior probability lies between \(L\) and \(U\). For a \(\text{Beta}(\alpha, \beta)\) posterior, this is computed as the interval between the 0.025 and 0.975 quantiles of that distribution — meaning we believe with 95% posterior probability that the true parameter falls within this range.

The 95% credible interval for \(\text{Beta}(91, 19)\) is approximately [0.75, 0.89].


(b) What if Customer B was in the online music sales domain rather than games?

Click to reveal solution

If Customer B is in a different domain (music vs games), we should not use the Customer A results as a strong prior, since the model's accuracy in game sales may not transfer to music sales.

Instead, we should use a weakly informative or uninformative prior, for example \(\text{Beta}(1, 1)\) (uniform):

\[\theta \sim \text{Beta}(1, 1)\]

Updating with Customer B's data:

\[\theta \mid \text{data}_B \sim \text{Beta}(1 + 6,\; 1 + 4) = \text{Beta}(7, 5)\]

The posterior mean is:

\[\mathbb{E}[\theta] = \frac{7}{12} \approx 0.583\]

Now the estimate (≈ 58.3%) is much lower and much more uncertain. The 95% credible interval for \(\text{Beta}(7, 5)\) is approximately [0.31, 0.83] — very wide, reflecting that we have only 10 observations and no relevant prior information.

Key insight: The choice of prior matters. Using domain knowledge appropriately (same domain → informative prior, different domain → weak prior) is a critical modeling decision that directly affects the accuracy estimate and its uncertainty.

Exercise 7: Comparing Classifiers

Two teams each build a customer support request (CSR) classifier that decides whether a request is urgent (binary classifier).

Which team has more reliable estimates from their test runs, and why? (We are not asking which team is more likely to have the best classifier.)

Click to reveal solution

Both teams have roughly equally reliable test estimates — Team A's are slightly more reliable (200 test examples vs 180).

The reliability of an accuracy estimate depends on the absolute size of the test set, not the total dataset size. The standard error of an estimated proportion \(\hat{p}\) is:

\[\text{SE} = \sqrt{\frac{\hat{p}(1-\hat{p})}{n_{\text{test}}}}\]

Only \(n_{\text{test}}\) appears in this formula — nothing about the training set or the total dataset. Team A tests on 200 examples and Team B on 180, so their standard errors are very similar.


(b) Now suppose Team A's classifier gets 120 out of 200 correct, and Team B's classifier gets 175 out of 180 correct. Assume a uniform prior \(\text{Beta}(1,1)\) on each classifier's true accuracy \(\theta\). Which team's posterior has the widest 95% credible interval, and why?

Click to reveal solution

With a \(\text{Beta}(1,1)\) prior (uniform) and Binomial data, the posterior is:

\[\theta \mid \text{data} \sim \text{Beta}(1 + k,\; 1 + n - k)\]

Team A (120 correct out of 200):

\[\theta_A \sim \text{Beta}(121, 81)\]

Team B (175 correct out of 180):

\[\theta_B \sim \text{Beta}(176, 6)\]

The variance of a \(\text{Beta}(\alpha, \beta)\) distribution is:

\[\text{Var} = \frac{\alpha \beta}{(\alpha+\beta)^2(\alpha+\beta+1)}\]

Team A:

\[\text{Var}_A = \frac{121 \times 81}{202^2 \times 203} = \frac{9801}{8{,}283{,}212} \approx 0.001183\]

Team B:

\[\text{Var}_B = \frac{176 \times 6}{182^2 \times 183} = \frac{1056}{6{,}061{,}692} \approx 0.000174\]

Team A's posterior has the wider 95% credible interval.

The Beta distribution's variance depends on how far the posterior mean is from 0.5. Team A's posterior mean is \(\frac{121}{202} \approx 0.60\), close to the high-uncertainty zone. Team B's posterior mean is \(\frac{176}{182} \approx 0.967\), far toward 1, where the distribution is tightly concentrated. So even though both teams have similar test set sizes, Team A's estimate of accuracy is considerably less precise.

Exercise 8: Donations at a Concert

An amateur university band passes around a pot for donations after a concert. There are 50 people in the audience. Each person gives money independently with the same distribution (IID). Each individual has the following donation distribution:

Donation ($) 0 1 5 10 20
Probability 0.10 0.20 0.35 0.30 0.05

(a) What is the expected amount of money that each person gives?

(b) What is the variance of the amount of money that each person gives?

(c) Give a probability distribution that approximates the total amount of money that the band earns.

(d) What is the approximate probability that the band makes at least $350?

Click to reveal solution

(a) We compute \(E[X]\) directly:

\[E[X] = 0(0.10) + 1(0.20) + 5(0.35) + 10(0.30) + 20(0.05) = 0 + 0.20 + 1.75 + 3.00 + 1.00 = \$5.95\]

(b) First compute \(E[X^2]\):

\[E[X^2] = 0^2(0.10) + 1^2(0.20) + 5^2(0.35) + 10^2(0.30) + 20^2(0.05) = 0 + 0.20 + 8.75 + 30.00 + 20.00 = 58.95\]

\[\text{Var}(X) = E[X^2] - (E[X])^2 = 58.95 - (5.95)^2 = 58.95 - 35.4025 = 23.5475\]

(c) Let \(S = X_1 + X_2 + \cdots + X_{50}\). Since the donations are IID with \(n = 50\), by the CLT:

\[S \approx \mathcal{N}(\mu_S,\, \sigma^2_S) \quad \text{where} \quad \mu_S = 50 \times 5.95 = 297.50,\quad \sigma^2_S = 50 \times 23.5475 = 1177.375\]

So \(S \approx \mathcal{N}(297.50,\; 1177.375)\).

(d) Since \(S \sim \mathcal{N}(297.50,\; 1177.375)\), we can directly compute:

\[P(S \geq 350) = 1 - P(S < 350) \approx 0.063\]

Exercise 9: Sum of Normal Random Variables

Let \(X \sim \mathcal{N}(\mu = 1,\; \sigma^2 = 2)\) and \(Y \sim \mathcal{N}(\mu = 1,\; \sigma^2 = 2)\).

What is the distribution of \(2X + Y\)?

Be sure to state any assumptions you make about the relationship between \(X\) and \(Y\).

Click to reveal solution

Assumption: \(X\) and \(Y\) are independent.

A linear combination of independent normal random variables is also normal. We compute the mean and variance:

\[E[2X + Y] = 2E[X] + E[Y] = 2(1) + 1 = 3\]

\[\text{Var}(2X + Y) = 4\cdot\text{Var}(X) + \text{Var}(Y) = 4(2) + 2 = 10\]

Therefore: \(2X + Y \sim \mathcal{N}(3,\; 10)\).

Exercise 10: Rolling Past 300

A fair 6-sided die is repeatedly rolled until the total sum of all rolls exceeds 300. Approximate the probability that at least 80 rolls are necessary to reach a sum exceeding 300.

Click to reveal solution

"At least 80 rolls are necessary" means that after 79 rolls the sum has not yet exceeded 300, i.e. \(S_{79} \leq 300\).

For a fair die, each roll \(X_i\) has:

\[E[X] = \frac{7}{2} = 3.5 \qquad \text{Var}(X) = \frac{35}{12} \approx 2.9167\]

Let \(S_{79} = X_1 + \cdots + X_{79}\). By the CLT:

\[E[S_{79}] = 79 \times 3.5 = 276.5 \qquad \text{Var}(S_{79}) = 79 \times \frac{35}{12} \approx 230.417 \qquad \sigma_{S_{79}} \approx 15.18\]

Since \(S_{79} \sim \mathcal{N}(276.5,\; 230.417)\), we can directly compute:

\[P(S_{79} \leq 300) \approx 0.9392\]

There is approximately a 93.9% chance that at least 80 rolls are needed.

Exercise 11: Comparing Program Runtimes

Program A runs 20 algorithms in sequence; each has runtime IID with mean = 50 s and variance = 100 s².

Program B runs 20 algorithms in sequence; each has runtime IID with mean = 52 s and variance = 200 s².

(a) What is the approximate probability that Program A completes in less than 950 seconds?

(b) What is the approximate probability that Program B completes in less than 950 seconds?

(c) What is the approximate probability that Program A completes in less time than Program B?

Click to reveal solution

(a) Let \(S_A = A_1 + \cdots + A_{20}\). By the CLT:

\[E[S_A] = 20 \times 50 = 1000 \qquad \text{Var}(S_A) = 20 \times 100 = 2000\]

So \(S_A \sim \mathcal{N}(1000,\; 2000)\), and we directly compute \(P(S_A < 950) \approx 0.1318\).

(b) Let \(S_B = B_1 + \cdots + B_{20}\). By the CLT:

\[E[S_B] = 20 \times 52 = 1040 \qquad \text{Var}(S_B) = 20 \times 200 = 4000\]

So \(S_B \sim \mathcal{N}(1040,\; 4000)\), and we directly compute \(P(S_B < 950) \approx 0.0774\).

(c) Consider \(D = S_A - S_B\). Assuming independence between programs:

\[E[D] = 1000 - 1040 = -40 \qquad \text{Var}(D) = 2000 + 4000 = 6000\]

So \(D \sim \mathcal{N}(-40,\; 6000)\), and we directly compute \(P(D < 0) \approx 0.6972\).

There is approximately a 69.7% chance that Program A finishes before Program B.