import numpy as np
from sklearn import preprocessing, model_selection, neighbors
import pandas as pd

######## Import data from file & remove useless data
df = pd.read_csv('breast-cancer.data.txt')
# Missing values denoted by '?' hence replace them
df.replace('?','-99999', inplace=True)
df.drop(['id'], 1, inplace=True)


####### Define features(X) & label(y)
X = np.array(df.drop(['class'], 1))
y = np.array(df['class'])

####### Split data into training & testing
X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, test_size=0.2)

####### Define classifier
clf = neighbors.KNeighborsClassifier()
clf.fit(X_train, y_train)

accuracy = clf.score(X_test, y_test)

####### Prediction
example_measures = np.array([[4,2,1,1,1,2,3,2,1],[4,2,1,1,1,2,3,2,1]])
# parameters of reshape=> 2 = how many arrays for prediction
example_measures = example_measures.reshape(len(example_measures), -1)
prediction = clf.predict(example_measures)
print(prediction)
