You are on page 1of 2

Untitled2.

ipynb - Colaboratory 13/04/23, 2)15 PM

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC

from matplotlib import pyplot as plt


%matplotlib inline

url = 'https://raw.githubusercontent.com/melwinlobo18/K-Nearest-Neighbors/master/Dataset/data
df = pd.read_csv(url) # Dataset - Breast Cancer Wisconsin Data
df['diagnosis'] = df['diagnosis'].map({
'M': 1,
'B': 2
}) # Label values - 1 for Malignant and 2 for Benign
labels = df['diagnosis'].tolist()
df['Class'] = labels #Cpying values of diagnosis to newly clreated labels column
df = df.drop(['id', 'Unnamed: 32', 'diagnosis'],
axis=1) #Dropping unncessary columns
df.head() #Displaying first five rows of the dataset
df

target_names = ['', 'M', 'B']


df['attack_type'] = df.Class.apply(lambda x: target_names[x])
df.head()

df1 = df[df.Class == 1]
df2 = df[df.Class == 2]

plt.xlabel('radius_mean')
plt.ylabel('texture_mean')
plt.scatter(df1['radius_mean'], df1['texture_mean'], color='green', marker='+')
plt.scatter(df2['radius_mean'], df2['texture_mean'], color='blue', marker='.')

X = df.drop(['Class', 'attack_type'], axis='columns')


X.head()

y = df.Class
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
print(len(X_train))
print(len(X_test))

model = SVC(kernel='linear')
model.fit(X_train, y_train)
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=None,
https://colab.research.google.com/drive/1V9VmZkQQXCjpTzq262PuOo_y_InbcZL3#scrollTo=O3whlWhDxQwg Page 1 of 2
Untitled2.ipynb - Colaboratory 13/04/23, 2)15 PM

kernel='linear', max_iter=-1, probability=False, random_state=None,


shrinking=True, tol=0.001, verbose=False)
predictions = model.predict(X_test)
print(predictions)

percentage = model.score(X_test, y_test)


from sklearn.metrics import confusion_matrix
res = confusion_matrix(y_test, predictions)
print("Confusion Matrix")
print(res)from sklearn.metrics import confusion_matrix
print(f"Test Set: {len(X_test)}")
print(f"Accuracy = {percentage*100} %")

Colab paid products - Cancel contracts here

! 0s completed at 2:10​PM

https://colab.research.google.com/drive/1V9VmZkQQXCjpTzq262PuOo_y_InbcZL3#scrollTo=O3whlWhDxQwg Page 2 of 2

You might also like