From bbc1851e2b625aa8b53673318077c9a3b4543638 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 15:23:20 +0000 Subject: [PATCH 1/2] Initial plan From eb8bd15032f2264dffe27a5b20d9f5e32f46a667 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 15:27:27 +0000 Subject: [PATCH 2/2] Make mesh step size configurable with clear documentation Co-authored-by: Baddsu51 <85847277+Baddsu51@users.noreply.github.com> --- config.yaml | 3 ++- src/models/svm_classifier.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index dfad2aa..9e80fc1 100644 --- a/config.yaml +++ b/config.yaml @@ -28,4 +28,5 @@ models: kernel: "rbf" # or 'linear', 'poly', etc. C: 1.0 # Must be > 0 probability: true # Necessary for AUC and predict_with_details - class_weight: "balanced" # or null (write null without quotes in YAML for None) \ No newline at end of file + class_weight: "balanced" # or null (write null without quotes in YAML for None) + mesh_step_size: 0.02 # Step size for decision boundary visualization mesh grid (smaller = higher resolution) \ No newline at end of file diff --git a/src/models/svm_classifier.py b/src/models/svm_classifier.py index 96124d3..f6a58d0 100644 --- a/src/models/svm_classifier.py +++ b/src/models/svm_classifier.py @@ -34,11 +34,18 @@ def _build_model(self): random_state=self.params.get('random_state', default_params.get('random_state', 42)) ) - def plot_decision_boundary(self, X, y, title="SVM Decision Boundary"): + def plot_decision_boundary(self, X, y, title="SVM Decision Boundary", step_size=None): """ Visualizes the decision boundary, margins, and support vectors. NOTE: This method strictly requires 2D feature data. + + Args: + X: Feature data (must be 2D) + y: Target labels + title: Plot title (default: "SVM Decision Boundary") + step_size: Mesh grid step size for visualization resolution (default: from config.yaml). + Smaller values increase resolution but may slow down plotting. """ if self.model is None: raise RuntimeError("Model not trained. Call train() first.") @@ -54,7 +61,13 @@ def plot_decision_boundary(self, X, y, title="SVM Decision Boundary"): "Tip: Use PCA to reduce to 2D or select only 2 columns." ) - h = 0.02 # Step size + # Get step size from config if not provided + if step_size is None: + config = get_config() + default_params = config.get_param('models.svm', {}) + step_size = default_params.get('mesh_step_size', 0.02) + + h = step_size # Mesh grid step size for visualization resolution x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1 y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1 xx, yy = np.meshgrid(np.arange(x_min, x_max, h),