Classification is a supervised machine learning method where the model tries to predict the correct label of a given input data. One of the algorithms used for classification is “K-Nearest Neighbor Classifier”.
Here, we use the stars.csv dataset for classification purposes and you can download the dataset from the link on top of this page.
This dataset has 6 features:
“Temperature”, “Relative Luminosity”, “Relative Radius”, “Absolute Magnitude”, “General Obs. Color” and “SMASS Spec.”
And the label for each item in the dataset is the type of Star, which has 6 values:
“Red Dwarf”, “Brown Dwarf”, “White Dwarf”, “Main Sequence”, “Super Giants” and “Hyper Giants”.
In the above form, you enter the values of 6 features and the model returns the type of star in a pop-up form. As 2 features of our dataset are Categorical and 4 of them are Numerical, for using K-Nearest Neighbor for this mixed dataset, we need to convert categorical features to numerical labels and then we could use the K-Nearest Neighbor Classifier.
Formula for "Relative Luminosity": L/Lo (Lo = 3.828 x 1026 Watts → Avg Luminosity of Sun)
Formula for "Relative Radius": R/Ro (Ro = 6.9551 x 108 m → Avg Radius of Sun)
Notice that the values and ranges of each feature is as below:
1939 < Temperature (K) < 40000
0.00008 < Relative Luminosity < 849420
0.0084 < Relative Radius < 1948.5
-11.92 < Absolute Magnitude < 20.06
Color Codes:
0 → Blue , 1 → Blue White , 2 → Orange
3 → Orange-Red , 4 → Pale yellow orange , 5 → Red
6 → White , 7 → Whitish , 8 → Yellow White
9 → Yellowish
Spectral Classes:
0 → A , 1 → B , 2 → F , 3 → G , 4 → K , 5 → M , 6 → O
For more information about Spectral Classes, see this link .
The sample code used to train a “K-Nearest Neighbor” classification model, is provided in the link on top of this page. Each time you run this form and classification predictions happen, the values will store in the database, and with the link “result” on top of this page, you will see the previous results of the model prediction. Your recent run will be added to the end of this list.