EE 541 - Unit 5
Dr. Brandon Franzke
Fall 2026
Example: A Text-Message Spam Filter
Data: 17,898 human-labeled pulsar candidates from a radio-telescope survey
Measurement \(x\): the mean of the candidate’s pulse profile
Decision: pulsar or noise, from \(x\) alone
Overlap: the same \(x\) occurs in both classes
Data: HTRU2, R. J. Lyon et al., MNRAS 2016; UCI Machine Learning Repository (CC BY 4.0)
Rule: decide pulsar if \(x < T\), noise otherwise
Two errors:
Example, \(T = 80\), counted over the 17,898 candidates:
Raising \(T\): fewer misses, more false alarms
Decision rule \(\delta(\mathbf{x})\): an action for each \(\mathbf{x}\)
Loss \(c(y, a)\): cost of action \(a\) when the class is \(y\)
Risk:
Example, counted over the candidates:
Bayes rule \(\delta^*\): the rule with the smallest risk
Risk by iterated expectations:
Bayes rule:
Binary, with \(\pi(\mathbf{x}) = P(Y=1 \mid \mathbf{x})\):
\(\pi(\mathbf{x}) = \mathbb{E}[Y \mid X = \mathbf{x}]\): for \(Y \in \{0,1\}\), the posterior is the MMSE predictor
Example: a Gaussian fitted to each class, \(\mathcal{N}(116.6, 17.5^2)\) for noise and \(\mathcal{N}(56.7, 30.0^2)\) for pulsars, with \(P(Y{=}1) = 0.092\)
0-1 loss: every error costs 1, so the risk is the probability of error
Expected loss of deciding class \(a\): \(1 - P(Y=a \mid \mathbf{x})\)
MAP rule: the class with the largest posterior
Bayes error: the error rate of the MAP rule
Example: decide pulsar when \(x < 73.8\), where the fitted \(\pi(x) = 1/2\)
Decide pulsar when its expected loss is smaller:
Threshold on the posterior:
Example, \(c_{01} = 1\), \(c_{10} = 10\): \(\tau^* = 1/11 = 0.091\)
| Rule | Pulsar if | Misses | False alarms |
|---|---|---|---|
| MAP, \(\tau = 0.5\) | \(x < 73.8\) | 30% of pulsars | 0.6% of noise |
| Costs, \(\tau^* = 0.091\) | \(x < 90.1\) | 16% of pulsars | 7.2% of noise |
Odds of an event: \(\text{odds}(A) = \dfrac{P(A)}{P(A^c)} = \dfrac{P(A)}{1 - P(A)}\)
Likelihood ratio:
Bayes theorem, odds form (\(p(\mathbf{x})\) cancels):
Log form: \(\log\) posterior odds \(= \log \Lambda(\mathbf{x}) + \log\) prior odds
Example at \(x = 80\), fitted densities:
Decide pulsar when posterior odds \(> c_{01}/c_{10}\)
Substituting posterior odds \(= \Lambda(\mathbf{x}) \times\) prior odds:
Example: \(\eta = \dfrac{1}{10} \cdot \dfrac{16{,}259}{1{,}639} = 0.99\)
| \(\eta\) from | \(\eta\) | Pulsar if |
|---|---|---|
| Neither (equal costs, equal priors) | 1 | \(x < 90.0\) |
| Prior only | 9.9 | \(x < 73.8\) |
| Costs and prior | 0.99 | \(x < 90.1\) |
Reject option: a third action, defer the decision to a human reviewer, at cost \(c_r\)
Expected loss of each action:
Bayes rule, the smallest of the three:
Two thresholds only if \(c_r < \dfrac{c_{01}\,c_{10}}{c_{01} + c_{10}}\), otherwise a single threshold, \(\tau^*\)
Example, \(c_{01} = 1\), \(c_{10} = 10\), \(c_r = 0.3 < 10/11 = 0.91\), two thresholds:
Gaussian fits to the pulsar data (spreads 17.5 and 30.0): log-odds \(= \log \Lambda(x) +\) log prior odds
General: classes \(\mathcal{N}(\boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k)\)
Shared \(\boldsymbol{\Sigma}\): the quadratic terms cancel
Different variances, one feature: a quadratic term remains
Data: labeled pairs \((\mathbf{x}_i, y_i)\), not densities and not \(\pi(\mathbf{x})\)
Estimating \(\pi(\mathbf{x})\) from labeled pairs:
Least squares on 0/1 labels estimates \(\mathbb{E}[Y \mid X = x] = P(Y = 1 \mid x)\)
Linear model \(\hat\pi(x) = w\,x + b\):
Example: least-squares line through the 17,898 pulsar labels
Odds \(\dfrac{\pi}{1 - \pi}\): from 0 to \(\infty\)
Log-odds \(\log \dfrac{\pi}{1 - \pi}\): any real number
Example: observed pulsar fraction per bin of \(x\) (figure)
Linear score \(z = \mathbf{w}^T\mathbf{x} + b\), which can be any real number
Model: the score is the log-odds
Inverting: odds \(= e^{z}\), so \(\pi = e^{z}/(1 + e^{z})\)
Sigmoid:
Not least squares on log-odds: a label’s log-odds is \(\log(1/0)\) or \(\log(0/1)\)
Example, fitted to the pulsar data: \(w = -0.111\), \(b = 7.97\)
Log-odds \(= \log \Lambda(\mathbf{x}) + \log\) prior odds
\(\log \Lambda\) linear in \(\mathbf{x}\):
Word counts, as in spam filtering: independent Poisson counts per word give \(\log \Lambda\) linear in the count vector
Two alternatives to the sigmoid:
Fit: nearly the same
Log-odds only:
Reason for the sigmoid: this reading, not its fit
Estimating \(\pi(\mathbf{x})\), with \(d\) input features:
Parameters, Gaussian classes with a shared covariance:
| \(d\) | Class densities | Logistic regression |
|---|---|---|
| 1 (profile mean) | 4 | 2 |
| 8 (all eight pulsar statistics) | 53 | 9 |
| 784 (\(28 \times 28\) image) | 309,289 | 785 |
Assumptions:
Limitations:
Log-odds \(= \sum_j w_j x_j + b\)
Example, pulsar fit \(w = -0.111\):
Decision boundary \(\pi(\mathbf{x}) = \tau\): \(\;\mathbf{w}^T\mathbf{x} + b = \log \frac{\tau}{1 - \tau}\)
Hard threshold on the score: decide 1 if \(z > 0\)
Clamp \(0.5 + z/4\), cut to \([0, 1]\)
Sigmoid \(\sigma(z)\): rises from 0 to 1 around \(z = 0\)
Fitting by gradient needs that slope: with the threshold or the clamp, most changes in \(\mathbf{w}\) leave the output unchanged
Chain rule on \(\sigma(z) = (1 + e^{-z})^{-1}\):
Example: the slope of \(\pi(x)\) is \(w\,\pi(1 - \pi)\), largest in size at \(x = 72.1\), where it is \(-0.111 \times 1/4 = -0.028\)
Each label is a Bernoulli draw given its input:
Independent labels: the likelihood is a product
Negative log: the product becomes a sum
In floating point, the product underflows to 0 and the sum does not
Example: four labeled points \((x_i, y_i)\)
At \(w = 2\), \(b = -2\):
| \(x_i\) | \(y_i\) | \(\pi_i\) | loss |
|---|---|---|---|
| 0 | 0 | 0.12 | 0.13 |
| 1 | 1 | 0.50 | 0.69 |
| 1.5 | 0 | 0.73 | 1.31 |
| 2.5 | 1 | 0.95 | 0.05 |
\(\mathcal{L} = 2.18\)
Pulsar fit: the worst-predicted 1% of candidates carry 37% of \(\mathcal{L}\)
One label: \(z = \mathbf{w}^T\mathbf{x} + b\), \(\pi = \sigma(z)\)
Chain rule:
Weights and bias:
Squared error on \(\pi\) keeps the factor \(\pi(1 - \pi)\), which is near 0 when the prediction is confidently wrong (figure)
Stack the data: \(\mathbf{X} \in \mathbb{R}^{n \times d}\) with rows \(\mathbf{x}_i^T\), \(\boldsymbol{\pi} = \sigma(\mathbf{X}\mathbf{w} + b\mathbf{1})\)
Sum over labels:
Least squares, same form:
Example, four points at \(w = 2\), \(b = -2\) (figure):
Stationary point:
The \(b\) equation: \(\sum_i \pi_i = \sum_i y_i\)
Example, four points: \(w = 1.60\), \(b = -2.00\)
Zero start: \(\mathbf{w} = \mathbf{0}\), \(b = 0\)
Class-fraction start: \(\mathbf{w} = \mathbf{0}\), \(b = \log \dfrac{\bar y}{1 - \bar y}\)
One minimum: the loss is convex, so every start ends at the same \((\mathbf{w}, b)\)
Random starts: needed for networks, where units that start equal stay equal
One iteration:
Example, four points, zero start, \(\eta = 0.5\):
Step size: \(\eta < 2/\lambda_{\max}\) of the Hessian
Hessian over \(\boldsymbol{\theta} = (\mathbf{w}, b)\), with \(\tilde{\mathbf{X}} = [\mathbf{X} \;\; \mathbf{1}]\):
Positive semidefinite: for any \(\mathbf{v}\)
Example at the zero start: \(\mathbf{H} = \begin{bmatrix} 2.375 & 1.25 \\ 1.25 & 1 \end{bmatrix}\), eigenvalues 3.11 and 0.26
A minimum exists only if no hyperplane separates the classes
Newton: \(\boldsymbol{\theta} \leftarrow \boldsymbol{\theta} - \mathbf{H}^{-1}\mathbf{g}\), with \(\mathbf{g} = \tilde{\mathbf{X}}^T(\boldsymbol{\pi} - \mathbf{y})\), \(\mathbf{H} = \tilde{\mathbf{X}}^T\mathbf{S}\tilde{\mathbf{X}}\)
Rearranged:
Cost per step:
Example, pulsar data, zero start, steps to \(\hat w\) within a relative \(10^{-6}\):
Reference: the fit to all 17,898 pulsar candidates, \(\hat w = -0.111\)
Subsamples: 500 random subsets at each \(n\), each fit by Newton
| \(n\) | median \(\hat w\) | middle 50% of \(\hat w\) | no finite \(\hat w\) |
|---|---|---|---|
| 50 | \(-0.117\) | \(-0.170\) to \(-0.090\) | 163 of 500 |
| 200 | \(-0.115\) | \(-0.138\) to \(-0.099\) | 1 of 500 |
| 1000 | \(-0.111\) | \(-0.120\) to \(-0.105\) | 0 |
Subsets of one data set stand in for new samples from the same survey
Data: 5,574 human-labeled English text messages
Legitimate:
Spam:
Decision: deliver the message, or send it to the spam folder
Costs: a lost legitimate message is worse than a delivered spam
Model: logistic regression on the words of each message
Data: T. A. Almeida, J. M. Gómez Hidalgo, A. Yamakami, SMS Spam Collection, UCI Machine Learning Repository (2011), CC BY 4.0.
Vocabulary: every word that appears in at least 5 of the 4,000 training messages
Features: \(x_j\) = number of times word \(j\) appears in the message
def tokenize(message): message = re.sub(r"&\w+;", " ", message) # HTML escapes in the raw text return re.findall(r"[a-z0-9£]+", message.lower()) def count_vector(message): x = np.zeros(len(vocab)) for word in tokenize(message): if word in column: # word -> column index x[column[word]] += 1 return x
Example: “Free Msg: get Gnarls Barkleys “Crazy” ringtone TOTALLY FREE just reply GO to this message right now!”
x = count_vector('Free Msg: get Gnarls Barkleys "Crazy" ringtone ' 'TOTALLY FREE just reply GO to this message right now!') print({vocab[j]: int(x[j]) for j in np.flatnonzero(x)})
{'crazy': 1, 'free': 2, 'get': 1, 'go': 1, 'just': 1, 'message': 1, 'msg': 1, 'now': 1, 'reply': 1, 'right': 1, 'ringtone': 1, 'this': 1, 'to': 1}
The loop from the four-point example, with the gradient averaged over the \(n = 4{,}000\) messages:
def sigmoid(z): return 1 / (1 + np.exp(-z)) n = len(y_train) w = np.zeros(len(vocab)) b = np.log(y_train.mean() / (1 - y_train.mean())) # class-fraction start history = [] for step in range(1, 3001): p = sigmoid(X_train @ w + b) w -= 0.5 * X_train.T @ (p - y_train) / n b -= 0.5 * (p - y_train).mean() if step % 25 == 0: p_test = sigmoid(X_test @ w + b) history.append((step, ((p > 0.5) == y_train).mean(), ((p_test > 0.5) == y_test).mean(), np.linalg.norm(w)))
Newton: a \(1{,}472 \times 1{,}472\) Hessian to form and solve at every step
Odds factor \(e^{w_j}\): each occurrence of word \(j\) multiplies the odds of spam by it
Largest factors:
Smallest factors:
Bias \(b = -4.55\): odds of spam 0.011 for a message with no vocabulary words
Score: \(z = b + \sum_j w_j x_j\), one term per word occurrence
Three test messages:
| Message | \(z\) | \(\pi\) |
|---|---|---|
| “For your chance to WIN a FREE Bluetooth Headset then simply reply back with “ADP”” | 2.02 | 0.88 |
| “Now am free call me pa.” | \(-1.31\) | 0.21 |
| “Latest News! Police station toilet stolen, cops have nothing to go on!” (spam) | \(-3.19\) | 0.04 |
Threshold from the costs, \(c_{01} = 10\), \(c_{10} = 1\):
Test messages (1,574, of which 200 spam):
| Threshold | Legitimate sent to spam | Spam delivered | Cost |
|---|---|---|---|
| \(\tau = 0.5\) | 5 | 22 | 72 |
| \(\tau^* = 0.91\) | 0 | 44 | 44 |
Lowest test cost: 37, at \(\tau = 0.69\), not at \(\tau^*\)
Spam test set: 1,574 messages, 200 spam (12.7%)
Accuracy, fraction correct:
Confusion matrix, \(\tau = 1/2\):
| sent to spam | delivered | |
|---|---|---|
| spam | TP = 178 | FN = 22 |
| legitimate | FP = 5 | TN = 1,369 |
Four counts:
At \(\tau^* = 0.91\): TP 156, FN 44, FP 0, TN 1,374
Accuracy and cost disagree whenever the two errors cost different amounts
Two rates, one per true class:
At \(\tau = 1/2\): TPR \(= 178/200 = 0.89\), FPR \(= 5/1{,}374 = 0.0036\)
ROC curve: (FPR, TPR) as \(\tau\) runs from 1 to 0
Area under the curve (AUC): 0.979
Precision: fraction of messages sent to spam that are spam
Same TPR and FPR, rarer spam, by Bayes theorem:
| Spam fraction | Precision |
|---|---|
| 12.7% (this test set) | 0.97 |
| 1% | 0.71 |
| 0.1% | 0.20 |
Calibrated: among messages given \(\pi \approx q\), a fraction \(q\) is spam
Test messages, grouped by \(\pi\):
| \(\pi\) range | messages | mean \(\pi\) | fraction spam |
|---|---|---|---|
| 0 to 0.1 | 1,349 | 0.009 | 0.008 |
| 0.1 to 0.5 | 42 | 0.23 | 0.26 |
| 0.5 to 0.9 | 27 | 0.72 | 0.81 |
| 0.9 to 1 | 156 | 0.99 | 1.00 |
Separate from ranking: rescaling \(\pi\) without reordering changes calibration and leaves the ROC curve unchanged
Log-loss: the negative log-likelihood per message
Spam model, by gradient step:
| step | training log-loss | test log-loss | \(|\mathbf{w}|\) |
|---|---|---|---|
| 300 | 0.081 | 0.094 | 5.0 |
| 3,000 | 0.027 | 0.065 | 11.6 |
| 20,000 | 0.008 | 0.066 | 22.0 |
Posterior: a vector \(\boldsymbol{\pi}(\mathbf{x}) = [\pi_1(\mathbf{x}), \ldots, \pi_K(\mathbf{x})]^T\), with \(\pi_k(\mathbf{x}) = P(Y = k \mid \mathbf{x})\)
Cost matrix \(\mathbf{C} \in \mathbb{R}^{K \times K}\): \(c_{ka}\) = cost of deciding \(a\) when the class is \(k\)
Expected loss of deciding \(a\):
Bayes rule: \(\delta^*(\mathbf{x}) = \arg\min_a R(a \mid \mathbf{x})\)
Example, \(K = 3\), class 3 costly to miss:
One-vs-rest: \(K\) binary logistic models, class \(k\) against the other \(K - 1\)
Example data: 342 penguins, three species
One-vs-rest on these birds:
Argmax of the \(K\) outputs still gives a label
Expected losses \(\mathbf{C}^T\boldsymbol{\pi}\) need a probability vector
Data: Palmer Penguins, A. M. Horst, A. P. Hill, K. B. Gorman, 2020 (CC0); collected by K. Gorman and Palmer Station LTER
Softmax of scores \(\mathbf{z} \in \mathbb{R}^K\):
Example, \(\mathbf{z} = [2, 1, -1]\):
Scores tripled, \(\mathbf{z} = [6, 3, -3]\): \([0.953, 0.047, 0.0001]\)
Log of each numerator of Bayes theorem, classes \(\mathcal{N}(\boldsymbol{\mu}_k, \boldsymbol{\Sigma})\):
Normalizing: the shared term cancels
Example: one Gaussian per species with a shared covariance, fit to the 240 training penguins
Model: one weight vector and one bias per class
Pairwise log-odds, linear:
Assumption: every pairwise log-odds is linear in \(\mathbf{x}\); no model of \(p(\mathbf{x} \mid Y = k)\)
Example, flipper 205 mm: Adelie below a bill length of 44.1 mm, Gentoo to 47.6 mm, Chinstrap above
Shift by \(c\): the factor \(e^{c}\) cancels
Reference class \(z_1 = 0\): \((K - 1)(d + 1)\) parameters
\(K = 2\): \(\pi_2 = e^{z_2} / (1 + e^{z_2}) = \sigma(z_2)\), logistic regression
Without a reference class: adding one \(\mathbf{v}\) to every \(\mathbf{w}_k\) leaves \(\boldsymbol{\pi}\) unchanged
One label \(y \in \{1, \ldots, K\}\), one-hot \(\mathbf{y}\): the categorical cross-entropy, the negative log-likelihood of a discrete label
Softmax substituted:
Data set: \(\mathcal{L}(\mathbf{W}, \mathbf{b}) = \sum_{i=1}^{n} \ell_i\)
\(K = 2\), \(z_1 = 0\), labels \(y \in \{0, 1\}\): \(\ell = \log(1 + e^{z}) - y\,z\), the binary cross-entropy
Example: a test penguin, Chinstrap, bill 50.8 mm, flipper 210 mm
| Adelie | Chinstrap | Gentoo | |
|---|---|---|---|
| \(z_k\) | \(-3.28\) | 1.35 | 1.93 |
| \(\pi_k\) | 0.003 | 0.357 | 0.640 |
Overflow: \(e^{z}\) exceeds the largest float for
Shift by \(m = \max_k z_k\), which changes nothing:
Loss from the scores: \(\ell = -z_y + m + \log \sum_k e^{z_k - m}\)
\(K = 2\): \(\ell = \log(1 + e^{z}) - y\,z\) is np.logaddexp(0, z) - y * z
z = np.array([1000.0, 999.0, 998.0]) with np.errstate(over='ignore', invalid='ignore'): print(np.exp(z) / np.exp(z).sum()) # inf / inf m = z.max() print(np.exp(z - m) / np.exp(z - m).sum()) print(m + np.log(np.exp(z - m).sum()))
[nan nan nan]
[0.66524096 0.24472847 0.09003057]
1000.4076059644444
z, y = np.array([0.0, 800.0]), 0 # class 1 true, far behind with np.errstate(divide='ignore'): print(-np.log(softmax(z)[y])) # log of an underflowed 0 m = z.max() print(-z[y] + m + np.log(np.exp(z - m).sum()))
inf
800.0
Differentiating \(\ell = -z_y + \log \sum_k e^{z_k}\):
Weights, \(\mathbf{z} = \mathbf{W}\mathbf{x} + \mathbf{b}\):
Data set, one row per sample, \(\boldsymbol{\Pi}, \mathbf{Y} \in \mathbb{R}^{n \times K}\):
Example, the test Chinstrap, \(\mathbf{y} = [0, 1, 0]\), standardized \(\mathbf{x} = [1.26, 0.59]\):
Descent step on this bird:
Standardized features, averaged gradient:
W, b = np.zeros((3, 2)), np.zeros(3) for step in range(20000): P = softmax(X_train @ W.T + b) # n x K W -= 0.5 * (P - Y_train).T @ X_train / n b -= 0.5 * (P - Y_train).mean(axis=0)
Penguins, 240 training and 102 test birds:
Test confusion matrix, rows the true species:
| Adelie | Chinstrap | Gentoo | |
|---|---|---|---|
| Adelie | 43 | 0 | 0 |
| Chinstrap | 1 | 22 | 2 |
| Gentoo | 0 | 0 | 34 |
Separable: a hyperplane (in one dimension, a threshold) with every training point on the side of its class
Example: 50 pulsar candidates, 6 of them pulsars
Sharper threshold, lower loss: multiplying \(\mathbf{w}\) and \(b\) by \(c > 1\) keeps the boundary and steepens \(\pi(x)\)
Spam training messages: close to separable, \(\|\mathbf{w}\| = 22.0\) at step 20,000 and still growing
Penalized loss, bias not penalized:
Unique: Hessian \(\frac{1}{n}\tilde{\mathbf{X}}^T\mathbf{S}\tilde{\mathbf{X}} + \lambda\,\operatorname{diag}(1, \ldots, 1, 0)\) is positive definite
Finite: \(R_\lambda \to \infty\) as \(\|\mathbf{w}\| \to \infty\), also for separable data
Gradient step:
Example, the separable subset, \(\lambda = 0.01\): \(w = -2.60\) at step 1,000 and at step 100,000
MAP estimate:
Gaussian prior, independent \(w_j \sim \mathcal{N}(0, \tau^2)\):
Laplace prior, independent \(p(w_j) = \frac{1}{2s}e^{-|w_j|/s}\):
Narrower prior: larger penalty
One weight, loss \(\tfrac{1}{2}(w - a)^2\) around the unpenalized value \(a\):
| Penalty | \(\hat w\) | \(\hat w = 0\) when |
|---|---|---|
| \(\tfrac{\lambda}{2}w^2\) | \(\dfrac{a}{1 + \lambda}\) | \(a = 0\) |
| \(\lambda \lvert w \rvert\) | \(\operatorname{sign}(a)\max(\lvert a \rvert - \lambda,\, 0)\) | \(\lvert a \rvert \le \lambda\) |
Penalty slope at \(w = 0\):
Many weights: \(\hat w_j = 0\) whenever \(\lvert \partial(\text{loss}) / \partial w_j \rvert \le \lambda\) at the solution
Proximal gradient: a gradient step, then the soft threshold on every weight
def soft(v, t): return np.sign(v) * np.maximum(np.abs(v) - t, 0) p = sigmoid(X_train @ w + b) w = soft(w - eta * X_train.T @ (p - y_train) / n, eta * lam)
Spam model, 5,000 steps:
| \(\lambda\) | words kept | test accuracy | test log-loss |
|---|---|---|---|
| 0 | 1,471 | 98.3% | 0.065 |
| \(3 \times 10^{-4}\) | 194 | 97.9% | 0.076 |
| \(10^{-3}\) | 85 | 97.1% | 0.097 |
| \(3 \times 10^{-3}\) | 38 | 96.0% | 0.132 |
Subgradient steps, \(\lambda\operatorname{sign}(\mathbf{w})\) added to the gradient: no weight exactly 0 after 5,000 steps
5-fold cross-validation on the 4,000 training messages:
Spam model, L2: lowest average log-loss 0.058, at \(\lambda = 10^{-4}\)
Validation split: 800 of the 4,000 training messages; gradient descent on the other 3,200
Stopping rule: the step with the lowest validation loss
Relation to L2: from \(\mathbf{w} = \mathbf{0}\), \(\|\mathbf{w}\|\) grows with the number of steps
XOR: class 1 where \(x_1\) and \(x_2\) have opposite signs
Logistic fit on 400 points:
Every model in this lecture has this limit
Added feature \(x_1 x_2\): logistic regression on \((x_1, x_2, x_1 x_2)\)
Choosing the feature: \(x_1 x_2\) comes from knowing the pattern
Number of features, all monomials of degree 1 to \(k\) in \(d\) inputs: \(\binom{d + k}{k} - 1\)
| \(d\) | \(k = 2\) | \(k = 3\) |
|---|---|---|
| 2 | 5 | 9 |
| 30 | 495 | 5,455 |
| 784 (\(28 \times 28\) image) | 308,504 | 80,931,144 |
Neuron: a weighted sum plus a bias, then a nonlinearity
Fitting the neuron, as in this lecture:
Label at the output: \(y\) enters the gradient through \(\pi - y\)
Hidden layer: \(m\) logistic units on the input
Output unit: logistic regression on \(\mathbf{h}\)
XOR with \(m = 2\), weights set by hand (figure):
Output weights \(\mathbf{w}_2\): logistic regression on \(\mathbf{h}\)
Hidden weights \(\mathbf{W}_1\): no label at \(\mathbf{h}\), so no \(\pi - y\) there
Cost of the hidden layer: