From 3da65944e03c534afe2d56d6e0a6b41436aad0e5 Mon Sep 17 00:00:00 2001 From: zain-cs Date: Wed, 22 Oct 2025 21:12:41 +0500 Subject: [PATCH] Enhanced SVM: added accuracy report, flexible kernel, and visualization improvements --- support_vector_machine.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/support_vector_machine.py b/support_vector_machine.py index 01e4e6e..ddbfe7d 100644 --- a/support_vector_machine.py +++ b/support_vector_machine.py @@ -26,7 +26,9 @@ # Fitting the classifier into the Training set from sklearn.svm import SVC -classifier = SVC(kernel = 'linear', random_state = 0) +kernel_type = 'rbf' # options: 'linear', 'rbf', 'poly', 'sigmoid' +classifier = SVC(kernel=kernel_type, random_state=0) + classifier.fit(X_Train, Y_Train) # Predicting the test set results @@ -37,7 +39,14 @@ from sklearn.metrics import confusion_matrix cm = confusion_matrix(Y_Test, Y_Pred) +print("Confusion Matrix:\n", cm) + +# Add accuracy and classification report +from sklearn.metrics import accuracy_score, classification_report +print("Accuracy:", accuracy_score(Y_Test, Y_Pred)) +print("\nClassification Report:\n", classification_report(Y_Test, Y_Pred)) +# Step 7: Visualizing the Training Results # Visualising the Training set results from matplotlib.colors import ListedColormap @@ -51,9 +60,11 @@ for i, j in enumerate(np.unique(Y_Set)): plt.scatter(X_Set[Y_Set == j, 0], X_Set[Y_Set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j) -plt.title('Support Vector Machine (Training set)') -plt.xlabel('Age') -plt.ylabel('Estimated Salary') +plt.title(f'Support Vector Machine ({kernel_type.capitalize()} Kernel) - Training set') + +plt.xlabel('Age (years)') +plt.ylabel('Estimated Salary ($)') + plt.legend() plt.show()