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

MLAssCode

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)
5 views1 page

MLAssCode

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
You are on page 1/ 1

4/22/24, 10:25 PM Untitled

In [1]: # Import necessary libraries


from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score, classification_report

# Load the Iris dataset


iris = load_iris()
X = iris.data
y = iris.target

# 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/Untitled.ipynb?download=false 1/1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy