set1 = training_set
X1 = seq(min(set[, 3]) - 1, max(set[, 3]) + 1, by = 0.01)
X2 = seq(min(set[, 4]) - 1, max(set[, 4]) + 1, by = 0.01)
grid_set = expand.grid(X1, X2)
colnames(grid_set) = c('Age', 'EstimatedSalary')
y_grid = knn(train = training_set[, 3:4], test = grid_set, cl = training_set[, 5], k = 5)
ggplot(data = grid_set, aes(x = Age, y = EstimatedSalary, color = factor(y_grid))) +
geom_tile(aes(fill = factor(y_grid)), alpha = 0.3) +
geom_point(data = set1, aes(x = Age, y = EstimatedSalary, color = factor(Purchased))) +
labs(title = "K-NN Classification (Training Set)", x = "Age", y = "Estimated Salary") +
scale_fill_manual(values = c("tomato", "springgreen3")) +
scale_color_manual(values = c("red3", "green4"))