library (class)
library (datasets)

BreastCancer <- read.csv(file='breast.data.csv')
BreastCancer <- BreastCancer[-1] # drop sample column

## Split in train + test set
indexes <- sample(1:nrow(BreastCancer),as.integer(0.7*nrow(BreastCancer)))

trainData <- BreastCancer[indexes,]
testData <- BreastCancer[-indexes,]

## A 5-nearest neighbors model with no normalization
pred <- knn(train = trainData[, -11], test = testData[, -11], cl = trainData[,11], k=5)

confusionmatrix = as.matrix(table(Actual = testData[,11], Predicted = pred))
accuracy = sum(diag(confusionmatrix))/length(testData[,11])

print('Confusion Matrix')
print(confusionmatrix)
print('Accuracy')
print(accuracy)

