a simple KNN algorithm in KAGSA Programming Language
i use this small dataset that have [Cigarettes, Weight]
in X
and [0:Bad , 1:Good]
in y
.
i. | Cigarettes | Weight | |
---|---|---|---|
0 | 7 | 70 | 0 |
1 | 7 | 40 | 0 |
2 | 3 | 40 | 1 |
3 | 1 | 40 | 1 |
4 | 3 | 70 | 0 |
cigarettes.kg
:
include "KNeighbors.kgl"
// X : [Cigarettes, Weight]
// y : [0:Bad , 1:Good]
data = ``{
"x": [[7,70],[7,40],[3,40],[1,40],[3,70]],
"y": [0,0,1,1,0],
"k":2
}``
data = JSON.parse(data)
new_x = list(7,50)
pred = KNeighbors.KNN(data.k ,data.x , data.y, new_x)
if pred {
write 'Good'
}else {
write 'Bad'
}