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

Iris Data SVM Classification Guide

The document outlines a Python script that implements a Support Vector Classifier (SVC) using the Iris dataset. It includes data loading, preprocessing, model training, and evaluation, resulting in an accuracy score and a confusion matrix. The script utilizes libraries such as NumPy, Pandas, and Scikit-learn for machine learning tasks.

Uploaded by

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

Iris Data SVM Classification Guide

The document outlines a Python script that implements a Support Vector Classifier (SVC) using the Iris dataset. It includes data loading, preprocessing, model training, and evaluation, resulting in an accuracy score and a confusion matrix. The script utilizes libraries such as NumPy, Pandas, and Scikit-learn for machine learning tasks.

Uploaded by

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

import numpy as np

import pandas as pd
from sklearn.model_selection import train_test_split
from [Link] import StandardScaler
from [Link] import SVC
from [Link] import accuracy_score, confusion_matrix
from [Link] import load_iris
file_path = r'C:\Users\user\Downloads\[Link]'
iris_data = pd.read_csv(file_path)
X = iris_data.iloc[:, :-1].values # Features
y = iris_data.iloc[:, -1].values # Target variable
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = [Link](X_test)
svm_classifier = SVC(kernel='linear', random_state=42) # Using a linear kernel
svm_classifier.fit(X_train, y_train)
y_pred = svm_classifier.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy:", accuracy)
conf_matrix = confusion_matrix(y_test, y_pred)
print("Confusion Matrix:")
print(conf_matrix)

You might also like