Created
December 4, 2021 14:21
-
-
Save AnasBrital98/b73cbbefa459d655e01e2f5014869be8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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