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.
What the syntax does
QuadraticDiscriminantAnalysis(reg_param=0.1)- Creates a quadratic discriminant analysis classifier.
reg_param:0,0.1,0.5,1
reg_paramis between 0 and 1, default 0.- A positive value regularises the covariance toward a diagonal identity contribution.
- This lesson requires positive regularisation; judge it using training validation, not final-test performance.
Supplied for this practice
These objects are prepared afresh before your editor runs.
X- Feature dataframe for the declared population, preserving row indices.
X = df[['x1', 'x2']] y- Target series, aligned with
X.y = df.label X_train/X_test/y_train/y_test- Training feature rows from the declared split. Final-test feature rows from the declared split. Training targets, aligned with
X_train. Final-test targets, aligned withX_test.X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
Outputs you create
answer- The requested result, with the values, labels and row order described by this task.
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 |
- Fit regularised QDA and predict held-away labels.
answerHints
Think: Regularisation stabilises the class-specific covariance estimates.
Tools: QuadraticDiscriminantAnalysis with reg_param, fit and predict.
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.