KNN with SQL
Here's a quick implementation of supervised learning, the k-nearest neighbor (KNN) classification algorithm.
To get you up to speed, the premise of KNN is that neighboring data points are similar. Thus, we infer the characteristics of an unlabeled point based on its neighbors.
π In the code below, I classify a flower based on its sepal length and width.
Here's how I imagine it working.
1οΈβ£ First, we plot all the flowers with known sepal length, width, and classification (setosa/virginica) onto a graph.
2οΈβ£ Then, we plot flowers with unknown classifications onto the same graph.
3οΈβ£ For a flower with an unknown classification, we classify it as setosa if most of its nearest 50 neighbors are setosa and not virginica.
Here's some food for thought: You can do machine learning with SQL, but should you? Comment your thoughts below.
Code credit goes to FreeCodeCamp.