AI Lab Assignment-10 Ishaan Bhadrike
AI Lab Assignment-10 Ishaan Bhadrike
AI Lab Assignment-10 Ishaan Bhadrike
PRN - 21070122060
Objectives:
● Data Preprocessing and Feature Selection
● Support Vector Machine Algorithm Implementation
● Evaluation and Analysis
Algorithm:
1. Load and preprocess the dataset.
2. Split the data into training and testing sets.
3. Initialize the SVM classifier.
4. Train the SVM model on the training data.
5. Make predictions on the testing data.
6. Evaluate the model's performance using accuracy and
other relevant metrics.
7. Interpret the results and adjust the model if necessary.
Input:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score,
classification_report, confusion_matrix
from sklearn.preprocessing import LabelEncoder
data = pd.read_csv('Social_Network_Ads -
Social_Network_Ads.csv')
print(data.head())
non_numeric_columns =
data.select_dtypes(exclude=[np.number]).columns
print("Non-numeric columns:", non_numeric_columns)
if not non_numeric_columns.empty:
for column in non_numeric_columns:
# Apply label encoding to non-numeric columns
data[column] =
LabelEncoder().fit_transform(data[column])
print("\nClassification Report:")
print(classification_report(y_test, y_pred))
print("\nConfusion Matrix:")
print(confusion_matrix(y_test, y_pred))
Output:
Conclusion:
The Support Vector Machine (SVM) classification algorithm was
applied to a sample dataset, showcasing its efficacy in
categorizing instances accurately. Through preprocessing,
training, and evaluation steps, the SVM model demonstrated
satisfactory performance metrics. Further exploration could
involve parameter tuning and real-world deployment to enhance
its utility and validate its effectiveness.