image_output_1.png
from sklearn.model_selection import train_test_split

from sklearn.neighbors import LocalOutlierFactor

from sklearn.preprocessing import StandardScaler

from sklearn.svm import SVC

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

import seaborn as sns

import time

data = pd.read_csv('../input/breast-cancer/breast-cancer - breast-cancer.csv')

C = data['diagnosis'].value_counts()

corr = data.corr()
top_feature = corr.index[abs(corr['diagnosis']) > 0.5]
Important_Data = data[top_feature.values]
top_corr = data[top_feature].corr()

radius = data[['radius_mean', 'radius_se', 'radius_worst', 'diagnosis']]
texture = data[['texture_mean', 'texture_se', 'texture_worst', 'diagnosis']]
perimeter = data[['perimeter_mean', 'perimeter_se', 'perimeter_worst', 'diagnosis']]
area = data[['area_mean', 'area_se', 'area_worst', 'diagnosis']]
smoothness = data[['smoothness_mean', 'smoothness_se', 'smoothness_worst', 'diagnosis']]
compactness = data[['compactness_mean', 'compactness_se', 'compactness_worst', 'diagnosis']]
concavity = data[['concavity_mean', 'concavity_se', 'concavity_worst', 'diagnosis']]
concave_points = data[['concave points_mean', 'concave points_se', 'concave points_worst', 'diagnosis']]
symmetry = data[['symmetry_mean', 'symmetry_se', 'symmetry_worst', 'diagnosis']]
fractal_dimension = data[['fractal_dimension_mean', 'fractal_dimension_se', 'fractal_dimension_worst', 'diagnosis']]

X = Important_Data.drop(['diagnosis'], axis=1)
Y = Important_Data.diagnosis

columns = Important_Data.columns.tolist()
lof = LocalOutlierFactor()
y_pred = lof.fit_predict(X)
y_pred[0:30]
x_score = lof.negative_outlier_factor_
outlier_score = pd.DataFrame()
outlier_score['score'] = x_score
lofthreshold = -2.5
loffilter = outlier_score['score'] < lofthreshold
outlier_index = outlier_score[loffilter].index.tolist()
radius = (x_score.max() - x_score) / (x_score.max() - x_score.min())
outlier_score['radius'] = radius
X = X.drop(outlier_index)
Y = Y.drop(outlier_index).values

x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state=10)

MM = StandardScaler()
x_train = MM.fit_transform(x_train)
x_test = MM.fit_transform(x_test)

ACC = []
TM = []
SVC = SVC(kernel='linear', C=0.01)
time1 = time.time()
SVC.fit(x_train, y_train)
time2 = time.time()
time_interval = time2 - time1
print('   Training Time    :', time_interval, 'Seconds')
y_predicted_svm = SVC.predict(x_test)
print('Testing accurency   :', metrics.accuracy_score(y_test, y_predicted_svm) * 100, ' %')
y_predicted_svm1 = SVC.predict(x_train)
print('Training accurency  :', metrics.accuracy_score(y_train, y_predicted_svm1) * 100, ' %')
ACC.append(metrics.accuracy_score(y_test, y_predicted_svm) * 100)
TM.append(time_interval)