Skip to content

Instantly share code, notes, and snippets.

@AnasBrital98
Created December 4, 2021 14:21
Show Gist options
  • Save AnasBrital98/b73cbbefa459d655e01e2f5014869be8 to your computer and use it in GitHub Desktop.
Save AnasBrital98/b73cbbefa459d655e01e2f5014869be8 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
# Create a Dataset for The Model
x , y = make_blobs(n_samples=100 , n_features=2 , centers=2 , random_state=0)
# SVM works with -1 and 1 lables this is why we convert [0,1] to [-1,1]
y = np.where(y==0 , -1 , 1)
# divide The data
x_train , x_test , y_train , y_test = train_test_split(x , y , test_size=0.25)
# creating and Training The Model
clf = SVC(kernel='linear')
clf.fit(x_train , y_train)
# display the Model performance
y_pred = clf.predict(x_test)
accuracy = np.sum(y_pred == y_test) / len(y_test)
print(f'Model Accuracy : {accuracy * 100} % ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment