# Practical 8: Support Vector Machine (SVM)

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score

cancer = load_breast_cancer()
x, y = cancer.data, cancer.target
xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.2, random_state=42)

kernels = ['linear','poly','rbf']

best_kernel = None
best_accuracy = 0

for kernel in kernels:
    model = SVC(kernel = kernel)
    model.fit(xtrain, ytrain)
    ypred=model.predict(xtest)
    accuracy=accuracy_score(ytest, ypred)
    print('For ',kernel,' accuracy is ',accuracy)
    if accuracy>best_accuracy:
        best_accuracy=accuracy
        best_kernel=kernel

print('For the given problem best kernel is ',best_kernel,' with accuracy ',best_accuracy)
