11/6/24, 7:13 PM SVM_classification - Jupyter Notebook
In [1]: import numpy as np
import pandas as pd
In [2]: #After reading the dataset, divide the dataset into concepts and targets. Store the concepts in
dataset = pd.read_csv('Breast_Cancer.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
In [3]: #Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
In [4]: #Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
In [5]: # Training the Support Vector Machine (SVM) Classification model on the Training set
from sklearn.svm import SVC
classifier = SVC(kernel = 'linear', random_state = 0)
classifier.fit(X_train, y_train)
Out[5]: SVC(kernel='linear', random_state=0)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
In [6]: # Support Vector Machine (SVM) classifier model
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape='ovr', degree=3, gamma='auto_deprecated',
kernel='linear', max_iter=-1, probability=False, random_state=0,
shrinking=True, tol=0.001, verbose=False)
Out[6]: SVC(gamma='auto_deprecated', kernel='linear', random_state=0)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
localhost:8888/notebooks/Downloads/AIML PROGRAMS/AIML PROGRAMS/SVM_classification.ipynb 1/2
11/6/24, 7:13 PM SVM_classification - Jupyter Notebook
In [7]: from sklearn.metrics import confusion_matrix, accuracy_score
y_pred = classifier.predict(X_test)
cm = confusion_matrix(y_test, y_pred)
print(cm)
accuracy_score(y_test, y_pred)
[[102 5]
[ 5 59]]
Out[7]: 0.9415204678362573
In [ ]:
localhost:8888/notebooks/Downloads/AIML PROGRAMS/AIML PROGRAMS/SVM_classification.ipynb 2/2