library (class)
library (datasets)

Wine <- read.csv(file='wine.data.csv')

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

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

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

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

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

