The assessment is about machine learning. One row describes one recorded event, and the columns are numerical measurements.
The names provide context. You can reason about the ML task as inputs A, B, C, … and a label.
| Name in the notebook | Plain meaning |
|---|---|
lepton_pt | Sideways momentum of a charged lepton, such as an electron or muon. |
jet1_pt, jet2_pt | Sideways momenta of the two leading jets: reconstructed sprays of particles. |
missing_et summarises an imbalance in the measured transverse momenta.
It is one reconstructed number describing the event.
| Name in the notebook | Plain meaning |
|---|---|
dilepton_mass | Mass calculated for two leptons considered together. |
delta_phi_ll | Angle between the two lepton directions, viewed along the beam. |
delta_phi_lep_met | Angle between a lepton and the missing-momentum direction. |
| Role | In the supplied notebook |
|---|---|
| Inputs X | The numerical columns selected by detector_features. |
| Target y | signal: 1 for the named process of interest, 0 for background. |
Use the supplied information and the evidence in your investigation. No additional physics knowledge is required.
Use the current weights to calculate the output. With a target, we can also calculate a loss.
\[ \theta_{\mathrm{new}}=\theta-\eta\frac{\partial J}{\partial\theta} \]
The chain rule gives gradients. The optimiser uses those gradients to change the weights.
\[ 0+0+1+0+0+1+0+0+1=3 \]
One patch gives one response. The same kernel weights are reused at the next location.
Multiply matching entries and add. Slide the same weights across the image.
\[ p_k=\frac{e^{z_k}}{\sum_j e^{z_j}},\qquad\ell=-\sum_k y_k\ln p_k \]
| Observed label | Predicted probability | Loss |
|---|---|---|
| Correct class | 0.8 | −ln(0.8) ≈ 0.22 |
| Correct class | 0.1 | −ln(0.1) ≈ 2.30 |
The loss penalises assigning little probability to the observed class.
You can download an image model whose weights have already been trained.
For related image-recognition tasks, this can get you much of the way towards a useful model.
Reuse the feature extractor and fit a small new output head for your labels. You can also fine-tune some of the existing weights.
You still need suitable examples and an evaluation on new data.
| Example | Dimensions for each example |
|---|---|
| Two Iris measurements | 2: petal length and petal width |
| All four Iris measurements | 4 |
| An 8 × 8 grayscale image | 64: one brightness value per pixel |
| A hidden representation | One coordinate per hidden-unit output |
More columns give us more ways for two examples to differ.
There are 50 examples in every panel. Divide each input range into five bins. What happens to the number of possible cells?
\[ \mathrm{Number\ of\ cells}=5^d \]
| Input dimensions d | Cells | Examples per cell, on average |
|---|---|---|
| 1 | 5 | 10 |
| 2 | 25 | 2 |
| 3 | 125 | 0.4 |
| 10 | 9,765,625 | About 0.000005 |
Keeping comparable coverage can require far more data. This is one aspect of the curse of dimensionality.
Keep examples with 0.3 ≤ x₁ ≤ 0.7. The second input can have any value.
The highlighted strip contains 19 of these 50 points.
Now also require 0.3 ≤ x₂ ≤ 0.7. Only 8 of the 50 points remain inside the box.
\[ \mathrm{Fraction\ of\ area}=0.4\times0.4=0.16 \]
\[ d(x,x^{\prime})=\sqrt{\sum_j(x_j-x_j^{\prime})^2} \]
Which reference point is closest to the new input Q?
\[ d(Q,A)=\sqrt{(3-0)^2+(4-0)^2}=5 \]
The differences in the two inputs are 3 and 4. Square them, add them, then take the square root.
| Reference | Coordinates | Distance from Q |
|---|---|---|
| A | (3, 4) | √(9 + 16) = 5 |
| B | (1, 1) | √(1 + 1) ≈ 1.41 |
| C | (6, 0) | √(36 + 0) = 6 |
B is nearest in this two-input representation.
Add a third measurement, and let Q = (0, 0, 0).
| Reference | Three inputs | Distance from Q |
|---|---|---|
| A | (3, 4, 0) | √(9 + 16 + 0) = 5 |
| B | (1, 1, 8) | √(1 + 1 + 64) ≈ 8.12 |
A is now closer. Every input contributes, even if the extra measurement is unhelpful for the task.
With many inputs, the nearest example can be only slightly closer than a typical example.
In this example, distances become more alike relative to their typical size as we add inputs.
Imagine measuring the same laboratory with sensor A on one side and sensor B on the other.
How much of their change might they share?
Two temperature sensors measure the same changing conditions. Could we summarise much of their variation with one number?
Replace several correlated readings with fewer coordinates that retain most of their variation.
Here one main coordinate describes the laboratory warming or cooling.
\[ x_{ij}^{c}=x_{ij}-\mu_j \]
Subtract the training mean of each input. The origin now represents an average reading.
We will project the same temperature readings onto several directions. Which direction preserves the most spread?
\[ V=\frac{(-3)^2+(-1)^2+1^2+3^2}{4-1}=\frac{20}{3}\approx6.67 \]
This four-value example has mean zero. Variance summarises the squared distances from that mean.
\[ V_{0^\circ}=\frac{316.00}{79}\approx4.00 \]
There are 80 readings. Add their squared projected values and divide by 79.
\[ V_{20^\circ}=\frac{502.87}{79}\approx6.37 \]
The points spread further along this direction. The projected variance is larger.
\[ V_{70^\circ}=\frac{502.87}{79}\approx6.37 \]
This direction gives the same variance as 20° for this symmetric sensor example.
\[ V_{45^\circ}=\frac{606.72}{79}\approx7.68 \]
This direction preserves more of the temperature variation than the alternatives we tried.
PC1 is the direction with the largest projected variance. Here it is 45°, with variance 7.68.
PC1 describes the sensors warming and cooling together. What is left when the sensors differ?
\[ V_{135^\circ}=\frac{25.28}{79}\approx0.32 \]
With two inputs, one perpendicular direction remains. PC2 describes the smaller differences between A and B.
PC1 captures shared warmth. PC2 captures sensor differences. Keeping both preserves all the original variation.
PC1 alone retains 96% of the variation in the two temperature readings. We mainly lose the small A–B differences.
We still know whether the laboratory is warm or cool. We have given up some detail about how the two sensors differ.
\[ \frac{7.68}{7.68+0.32}=0.96 \]
One of two coordinates retains 96% of the temperature variance in this example.
That percentage describes spread in the inputs. It does not directly measure classification performance.
| Component | Variance | Share | Cumulative share |
|---|---|---|---|
| PC1 | 8.0 | 80% | 80% |
| PC2 | 1.0 | 10% | 90% |
| PC3 | 0.7 | 7% | 97% |
| PC4 | 0.3 | 3% | 100% |
In this illustrative example, how many components retain at least 95% of the variance?
Add the variances of the components we keep, then divide by the total variance.
\[ \frac{8+1+0.7}{8+1+0.7+0.3}=0.97 \]
This is the cumulative explained-variance ratio for the four-component example.
To predict house prices, we might use floor area and bedroom count.
| Input | Training mean | Training spread |
|---|---|---|
| Floor area | 1,500 ft² | 500 ft² |
| Bedrooms | 3 | 1 |
\[ \frac{2000-1500}{500}=1\qquad\frac{4-3}{1}=1 \]
Two illustrative flower species have similar petal lengths but different widths. Which direction varies most? Which distinguishes the species?
PC1 keeps more than 99% of the variance here, but loses the petal-width distinction between the species.
A small amount of variation can carry important predictive information.
\[ 8\times8=64 \]
These are the small scikit-learn digit images used below. Each square is one original pixel.
Reading the rows in order gives 64 input measurements. Nearby pixels often vary together.
Reshape each direction’s 64 weights into an 8 × 8 pattern. A component adds or subtracts a shared pattern from the mean image.
These are the same examples as the earlier gallery. More components retain finer detail; all 64 recover the original pixels.
For this training split, 21 components retain at least 90% of the variance and 28 retain at least 95%.
Two axes make the data visible, but retain only about 29% of its variance. Several classes overlap.
The square and circle examples have known labels. The star is a new set of petal measurements.
With k = 1, copy the label of the nearest reference flower: versicolor.
With k = 3, the votes are 2 versicolor, 1 virginica. The most common label wins.
With k = 5, the votes are 2 versicolor, 3 virginica. The neighbourhood can change the decision.
\[ d(x,x^{\prime})=\sqrt{(x_1-x_1^{\prime})^2+(x_2-x_2^{\prime})^2} \]
| Difference between two flowers | In centimetres | In millimetres |
|---|---|---|
| Petal length | 0.5 | 5 |
| Petal width | 0.2 | 2 |
If we change only width from centimetres to millimetres, its squared difference changes from 0.04 to 4.
The same physical flowers can acquire different numerical neighbours.
How do we solve this?
\[ x_j^{s}=\frac{x_j-\mu_j}{s_j} \]
Compare how far each measurement is from its training mean, relative to that measurement’s training spread.
Use the same stored means and scales for every new example. The preceding flower diagrams already do this.
A neighbour rule depends on distance. What problem could this pattern create?
kNN still selects k examples. The problem is that “nearest” can be only slightly closer than the other examples.
The distance ranking may become a weaker clue about meaningful similarity.
With k = 1, individual training examples can create small pockets of a class.
With k = 5, one unusual example has less influence on the vote.
With k = 25, local differences can disappear. A smoother boundary can also miss real structure.
A new example: 50 squares and 40 circles. Each cell belongs to its nearest training point. This is a Voronoi tessellation.
Now the nine nearest examples vote. The background shows their majority label at each location.
We set k = 90. Do the new inputs A, B and C receive different predictions?
All three receive the square label. The same 50 squares and 40 circles vote at every location.
All three maps use the same examples. Which will make the best predictions for new inputs?
Compare on held-out examples. Points show mean accuracy, and bars show spread across the five folds.
Here each fold fits on 72 points and checks the remaining 18.
| Nearby house | Observed price |
|---|---|
| Neighbour 1 | £210,000 |
| Neighbour 2 | £240,000 |
| Neighbour 3 | £270,000 |
\[ \widehat{y}=\frac{210,000+240,000+270,000}{3}=240,000 \]
For regression, uniform-weight kNN averages the neighbours’ target values.
model = KNeighborsClassifier(n_neighbors=5)
model.fit(X_train, y_train)
predicted = model.predict(X_new)
At prediction time, find nearby stored training examples and use their labels to vote.
One technique can create the representation that another uses. For example, PCA coordinates can become inputs to a neighbour rule.
Check the complete combination on validation data. Compression can retain useful structure or discard it.
A new flower starts as raw measurements. Scaling and PCA prepare the coordinates that kNN uses.
This ordered sequence is called a pipeline.
| Stage | Values for this flower |
|---|---|
| Raw measurements | (6.20, 2.80, 4.80, 1.80) |
| After scaling | (0.42, -0.60, 0.57, 0.77) |
| After PCA | (1.14, -0.34) |
| kNN prediction | virginica |
Here the inputs are all four Iris measurements: sepal length, sepal width, petal length and petal width.
| Step | What comes from the training flowers |
|---|---|
| Scaling | Each input’s mean and standard deviation. |
| PCA | The mean and directions used for projection. |
| kNN | The reference measurements and their labels. |
The complete fitted workflow includes all of these objects.
Use the stored training means, scales and PCA axes for validation flowers and future observations.
Their measurements pass through the sequence without fitting new steps.
from sklearn.pipeline import make_pipeline
model = make_pipeline(
StandardScaler(),
PCA(n_components=2),
KNeighborsClassifier(n_neighbors=5)
)
model.fit(X_train, y_train)
One fit call learns the transformations and prepares the neighbour model, in order.
predicted = model.predict(X_new)
Pass raw measurements in. The pipeline applies its fitted scaling, then PCA, then the neighbour vote.
For each fold, learn every step from the blue training rows. Use the orange rows to check the resulting predictions.
The usable model is the whole sequence that turns raw measurements into a prediction.