0% found this document useful (0 votes)
4 views2 pages

SVM Model Training on Iris Dataset

Uploaded by

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

SVM Model Training on Iris Dataset

Uploaded by

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

# Import necessary libraries

import numpy as np

import pandas as pd

import [Link] as plt

from sklearn.model_selection import train_test_split

from [Link] import StandardScaler

from [Link] import SVC

from [Link] import accuracy_score, classification_report, confusion_matrix

import seaborn as sns

# Load dataset (Replace [Link]' with your actual file)

# Make sure the dataset has numerical features for SVM

df = pd.read_csv("[Link]")

# Display the first few rows

print([Link]())

# Assume 'target' is the dependent variable, and others are independent features

X = [Link](columns=['target']) # Features

y = df['target'] # Target variable

# Split data into training (80%) and testing (20%) sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Standardizing features (SVM works better with scaled data)


scaler = StandardScaler()

X_train = scaler.fit_transform(X_train)

X_test = [Link](X_test)

# Create and train SVM model with RBF kernel

svm_model = SVC(kernel='rbf', C=1.0, gamma='scale', random_state=42)

svm_model.fit(X_train, y_train)

# Make predictions

y_pred = svm_model.predict(X_test)

# Evaluate the model

accuracy = accuracy_score(y_test, y_pred)

print("Accuracy:", accuracy)

print("\nClassification Report:\n", classification_report(y_test, y_pred))

# Confusion matrix

conf_matrix = confusion_matrix(y_test, y_pred)

[Link](figsize=(6,4))

[Link](conf_matrix, annot=True, cmap="Blues", fmt="d", xticklabels=[Link](y),


yticklabels=[Link](y))

[Link]("Predicted")

[Link]("Actual")

[Link]("Confusion Matrix")

[Link]()

You might also like