Understand the idea
QDA fits a covariance shape for each class, allowing curved boundaries. More parameters require more within-class information. Production regularises covariance and limits input feature count to ten.
Python skill: Fits separate class covariance structures.
Meet the syntax
QuadraticDiscriminantAnalysis(reg_param=0.1)QuadraticDiscriminantAnalysis- Fits separate class covariance structures.
reg_param=0.1- Regularises those covariance estimates toward a diagonal identity contribution to improve stability.
Follow the code
Use the numbered comments to connect each Python block to the workflow above.
model=QuadraticDiscriminantAnalysis(reg_param=.1).fit(X_train,y_train)
answer=model.predict(X_test)
This practice: Read and run the Python. Next: Change · QDA allows class-specific shapes.
Quadratic discriminant analysis · from idea to workflow
Question: Do classes need different covariance shapes?
Mechanism: Estimate a covariance per class to form curved boundaries.
Watch for: Many covariance parameters need enough examples per class; singular fits are unstable.
Interpret or debug · self-review: Explain why flexibility may hurt a small rare class and compare the simpler shared-covariance alternative.
Independent full workflow: ML-X14. First practise complete regression and classification in F11–F12; check readiness in W-K2–W-K3.
Given data · COV90
90 observations. Deterministic teaching observations; values illustrate the concept rather than a real population claim. The dataframe df is supplied afresh for each Run.
| x1 | x2 | label |
|---|---|---|
| -0.878151 | -0.683719 | A |
| -2.05616 | -0.327603 | A |
| 1.3031 | 1.29443 | A |
| -0.995383 | -0.240343 | A |
| -0.654128 | -0.314893 | A |
| -2.112 | -0.509527 | A |
| -1.49746 | 0.375701 | A |
| -1.09822 | -0.763825 | 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 |
|---|---|
| x1 | float64 |
| x2 | float64 |
| label | str |
Supplied setup · available if you need to inspect it
This code runs before your editor on every Run. These are the objects your exercise uses.
from sklearn.model_selection import train_test_split
X=df[['x1','x2']]
y=df.label
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=.2,random_state=42,stratify=y)
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
Your task · Follow
Fit regularised QDA and predict held-away labels.
Hint 1 — Think
Regularisation stabilises the class-specific covariance estimates.
Hint 2 — Tools
QuadraticDiscriminantAnalysis with reg_param, fit and predict.
Hint 3 — Approach
Fit the declared regularised recipe on training rows and predict held-away labels.
Explained solution
model=QuadraticDiscriminantAnalysis(reg_param=.1).fit(X_train,y_train)
answer=model.predict(X_test)
The regularisation choice is explicit and the evaluation rows do not estimate class shapes.
Helpful prior knowledge: LDA shares a covariance shape 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.