2.
Implementation of SVM using LibSVM:
o Implement Support Vector Machines (SVM) using LibSVM in Python.
o Train the model using different kernel functions (Linear, Polynomial, RBF, and
Sigmoid).
o Compare the accuracy and decision boundaries for different kernel types.
o Provide an analysis of which kernel performs best for different types of data
distributions.
from [Link] import load_iris
from sklearn.model_selection import train_test_split
from [Link] import SVC
from [Link] import accuracy_score
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
random_state=42)
kernels = ['linear', 'poly', 'rbf', 'sigmoid']
for k in kernels:
model = SVC(kernel=k)
[Link](X_train, y_train)
y_pred = [Link](X_test)
print(f"{k} kernel accuracy:", accuracy_score(y_test, y_pred))