image_output_5.png image_output_7.png image_output_4.png image_output_8.png image_output_6.png text_plain_output_1.png image_output_3.png image_output_2.png image_output_1.png image_output_10.png image_output_9.png
from sklearn.model_selection import train_test_split

from sklearn.neighbors import LocalOutlierFactor

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

import seaborn as sns

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)
print(x_train.shape)
print(y_train.shape)
print(x_test.shape)
print(y_test.shape)
x_train.head()