0% found this document useful (0 votes)
9 views1 page

SVM Classifier Performance on Iris Dataset

The document outlines a Python script that implements a Support Vector Machine (SVM) classifier using the Iris dataset. It includes steps for loading the dataset, splitting it into training and testing sets, training the classifier, making predictions, and evaluating the model's performance, achieving an accuracy of 1.00. The classification report indicates perfect precision, recall, and f1-scores for all classes.

Uploaded by

Pratham Dhiman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

SVM Classifier Performance on Iris Dataset

The document outlines a Python script that implements a Support Vector Machine (SVM) classifier using the Iris dataset. It includes steps for loading the dataset, splitting it into training and testing sets, training the classifier, making predictions, and evaluating the model's performance, achieving an accuracy of 1.00. The classification report indicates perfect precision, recall, and f1-scores for all classes.

Uploaded by

Pratham Dhiman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

4/22/24, 10:25 PM Untitled

In [1]: # Import necessary libraries


from [Link] import load_iris
from sklearn.model_selection import train_test_split
from [Link] import SVC
from [Link] import accuracy_score, classification_report

# Load the Iris dataset


iris = load_iris()
X = [Link]
y = [Link]

# Split the dataset into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_sta

# Initialize the SVM classifier


svm_clf = SVC(kernel='rbf', C=1.0, gamma='scale')

# Train the classifier on the training data


svm_clf.fit(X_train, y_train)

# Make predictions on the testing data


y_pred = svm_clf.predict(X_test)

# Evaluate the model


accuracy = accuracy_score(y_test, y_pred)
report = classification_report(y_test, y_pred, target_names=iris.target_names)

# Print the evaluation results


print(f'Accuracy: {accuracy:.2f}')
print('Classification Report:')
print(report)

Accuracy: 1.00
Classification Report:
precision recall f1-score support

setosa 1.00 1.00 1.00 10


versicolor 1.00 1.00 1.00 9
virginica 1.00 1.00 1.00 11

accuracy 1.00 30
macro avg 1.00 1.00 1.00 30
weighted avg 1.00 1.00 1.00 30

In [ ]:

localhost:8888/nbconvert/html/Desktop/ML/[Link]?download=false 1/1

Common questions

Powered by AI

The classification report metrics provide detailed insights into the classifier's performance across each class. Precision measures how many selected items are relevant, recall measures how many relevant items are selected, and F1-score balances precision and recall. In the SVM's evaluation on the Iris dataset, all these metrics are 1.00, indicating perfect recall and precision for all classes. This suggests the model was extremely accurate in correctly classifying each instance across setosa, versicolor, and virginica .

Accuracy indicates the proportion of correct predictions. While the SVM model achieves perfect accuracy of 1.00 on the Iris dataset, relying solely on accuracy can be deceptive. Without considering precision, recall, and the data's class distribution, it might overlook potential biases or misclassifications in minority classes. The presence of class imbalance in other contexts might result in high accuracy but poor performance for smaller classes, thus misleadingly evaluating true model efficacy .

A test size of 20% implies that only a fifth of the available Iris dataset is used for evaluating the model, while 80% is used for training. This ensures sufficient data for training, allowing the model to capture the varied characteristics of each class. However, it also restricts the amount of data to test against, which might limit the clarity of its generalization ability on subsets with different distributions. In small datasets, this split could introduce variance in results if the test data doesn't encapsulate the full spectrum of input classes .

The `train_test_split` function from sklearn introduces randomness in how it divides the dataset into training and testing parts, creating different partitions each time it is executed. By setting a `random_state`, the user can ensure consistent splits in multiple executions, which is crucial for reproducibility, especially in research and testing phases where consistent results across trials validate model performance. This benefits comparing models on the same data partitioning and facilitates debugging processes .

The RBF kernel is chosen for its capability to handle non-linear relationships by mapping inputs into higher-dimensional spaces. The Iris dataset might have inherent non-linear separability among the classes, making the RBF kernel suitable for this scenario. It balances the complexity and flexibility needed for accurate classification. Using RBF means the model can capture more complex patterns compared to linear kernels, but it might be more sensitive to overfitting on complex datasets .

In an SVM model, the hyperparameter 'C' controls the trade-off between maximizing the margin and minimizing classification error. A 'C' of 1.0 represents a standard penalty for misclassification and balances both concerns in the model. 'Gamma' defines the influence of a single training example; 'scale' is the default setting, which automatically scales it based on the input features. These settings likely balance preventing overfitting and maintaining model complexity, suitable for the relatively simple Iris dataset .

The Iris dataset was split into training and testing sets using a 80/20 ratio, with 80% of the data for training and 20% for testing. Train-test splits are crucial to evaluate model performance on unseen data, prevent overfitting, and estimate how the model generalizes to new inputs. By reserving data solely for testing purposes, the evaluation provides a realistic representation of the model's predictive capabilities on novel data .

The SVM classifier, when applied to the Iris dataset, achieves perfect classification performance with an accuracy of 1.00. The classification report indicates that the model has precision, recall, and F1-score of 1.00 for each class: setosa, versicolor, and virginica, based on a support of 10, 9, and 11 samples respectively. This suggests the model has an excellent predictive power with no misclassifications in this case .

The Iris dataset displays an even distribution across its classes with support values of 10 for setosa, 9 for versicolor, and 11 for virginica in the testing set. This balance ensures that the classification metrics—such as precision, recall, and F1-score—accurately reflect the model's performance without bias towards a majority class. It prevents skewed results and aids in demonstrating that the SVM classifier is equally effective across all class categories .

Using sklearn's SVC class provides a standard, well-optimized implementation of SVM, suitable for quick deployment and testing. Default random state values ensure reproducibility, critical for verifying results consistently. However, this may lead to variations in test results across different runs if not set explicitly, and specific data patterns may not be well-represented in every split. Therefore, while convenient, it limits customization and exploration of dataset-specific training dependencies .

You might also like