library(FNN)

df <- read.csv(file='auto-mpg.csv')

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

trainData <- df[indexes,1:7]
testData <- df[-indexes,1:7]

## A 3-nearest neighbors model 
model <- knn.reg(train = trainData, test = testData, y = trainData$mpg, k=3)
prediction <- model$pred

actual <- testData[,1:1]
print(cbind(actual, prediction))
