Understand the idea
Regularisation can stabilise a covariance estimate but cannot manufacture missing class information. Adding a regularising identity term also means unit choices can matter.
Python skill: Filter by class and use cov() to inspect the covariance information available to QDA.
Meet the syntax
df['label'].eq('A')
class_a.cov()df['label'].eq('A')- Creates a Boolean mask selecting examples from one class.
class_a.cov()- Returns feature-by-feature sample covariance. Its values depend on the measurement units.
Follow the code
Use the numbered comments to connect each Python block to the workflow above.
counts = df['label'].value_counts()
class_a = df.loc[df['label'].eq('A'), ['length', 'width']]
answer = class_a.cov()
This practice: Read and run the Python. Next: Change · Covariance support and regularisation limits.
Given data · CLASS180
180 observations. Deterministic teaching observations; values illustrate the concept rather than a real population claim. The dataframe df is supplied afresh for each Run.
| length | width | label |
|---|---|---|
| 236.033 | -0.805568 | A |
| 581.297 | 0.728558 | A |
| -1511.27 | -1.00866 | A |
| 99.0248 | -0.24496 | A |
| -13.0141 | -0.660765 | A |
| 681.179 | 0.602475 | A |
| 51.1472 | 0.873157 | A |
| 362.131 | -0.665605 | A |
Column meanings and units
Column names describe the supplied features and target. Keep the stated units and row identities when making comparisons.
Synthetic data are deliberately small and reproducible. Their patterns illustrate an idea; they are not evidence about a real population.
| Column | Stored type |
|---|---|
| length | float64 |
| width | float64 |
| label | str |
Your task · Follow
Count observations in each class and calculate the covariance of the two input measurements within class A. Store the covariance in answer.
Hint 1 — Think
Filter by class and use cov() to inspect the covariance information available to QDA.
Hint 2 — Tools
Use df['label'].eq('A'), class_a.cov(). Read the visible syntax meanings before editing.
Hint 3 — Approach
Count observations in each class and calculate the covariance of the two input measurements within class A. Store the covariance in answer. Keep the supplied row order and inspect the named output after running.
Explained solution
counts = df['label'].value_counts()
class_a = df.loc[df['label'].eq('A'), ['length', 'width']]
answer = class_a.cov()
QDA estimates a separate covariance structure for each class. A small class or nearly redundant measurements can make that estimate unstable. This table shows what is being estimated, not proof of stability. Use regularisation and validation; adding a parameter does not create new observations.
Helpful prior knowledge: QDA allows class-specific shapes These links are guidance, not locks.
Sources and API context
Examples run with this Playground’s scikit-learn 1.4.2 / Pyodide 0.26.4 runtime.