# Bootstrapping code

import matplotlib.pyplot as plt
from sklearn.neighbors import KNeighborsClassifier
from IPython.display import display, HTML, Markdown

example_X_data = [
    [2, 2],
    [3, 5],
    [4, 8],
    [5, 2],
    [6, 9],
    [2, 6],
    [8, 7]
]

example_X_labels = [
    "blue",
    "red",
    "red",
    "blue",
    "red",
    "red",
    "blue"
]

example_y_data = [
    [3, 3]
]
k = 3
neigh = KNeighborsClassifier(n_neighbors=k)
neigh.fit(example_X_data, example_X_labels)

nearest_neighbors = neigh.kneighbors(example_y_data)[1][0]

fig, ax = plt.subplots(figsize=(5, 5))
ax.scatter(*zip(*example_X_data), c=example_X_labels)
ax.scatter(*zip(*example_y_data), c="black", marker="x")
for n_i in nearest_neighbors:
    ax.plot([example_y_data[0][0], example_X_data[n_i][0]], [example_y_data[0][1], example_X_data[n_i][1]], 'gray', linestyle=':', marker='')
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
plt.show()
plt.close()
Markdown("The unlabeled instance is assigned to the *{}* class.".format(neigh.predict(example_y_data)[0]))