Update pages/KNN ALGORITHM.py
Browse files- pages/KNN ALGORITHM.py +7 -7
pages/KNN ALGORITHM.py
CHANGED
|
@@ -25,26 +25,26 @@ st.markdown("""
|
|
| 25 |
- Use resampling techniques (SMOTE, undersampling, oversampling) to balance.
|
| 26 |
""")
|
| 27 |
st.markdown("#### How kNN works")
|
| 28 |
-
st.markdown("##### 1️
|
| 29 |
st.write("Example: **K = 3**")
|
| 30 |
|
| 31 |
-
st.markdown("##### 2️
|
| 32 |
st.latex(r"x_q = [x_1, x_2, \ldots]")
|
| 33 |
|
| 34 |
-
st.markdown("##### 3️
|
| 35 |
st.latex(r"d(x_q, x_1) = d_1, \ d(x_q, x_2) = d_2, \ldots, d(x_q, x_n) = d_n")
|
| 36 |
st.write("👉 Usually Euclidean distance is used.")
|
| 37 |
|
| 38 |
-
st.markdown("##### 4️
|
| 39 |
st.write("Example: **d6, d7, d8, ...**")
|
| 40 |
|
| 41 |
-
st.markdown("##### 5️
|
| 42 |
st.write("If **K = 3**, choose the 3 nearest points → **x6, x7, x8**")
|
| 43 |
|
| 44 |
-
st.markdown("##### 6️
|
| 45 |
st.write("Example: y6, y7, y8")
|
| 46 |
|
| 47 |
-
st.markdown("##### 7️
|
| 48 |
st.write("The most frequent class among K neighbors becomes the predicted label.")
|
| 49 |
|
| 50 |
st.success("Example: If 2 are Green 🍏 and 1 is Red 🍎 → Query point is predicted as Green 🍏")
|
|
|
|
| 25 |
- Use resampling techniques (SMOTE, undersampling, oversampling) to balance.
|
| 26 |
""")
|
| 27 |
st.markdown("#### How kNN works")
|
| 28 |
+
st.markdown("##### 1️.Choose a K value")
|
| 29 |
st.write("Example: **K = 3**")
|
| 30 |
|
| 31 |
+
st.markdown("##### 2️.Take a query point")
|
| 32 |
st.latex(r"x_q = [x_1, x_2, \ldots]")
|
| 33 |
|
| 34 |
+
st.markdown("##### 3️.Calculate distance to all training points")
|
| 35 |
st.latex(r"d(x_q, x_1) = d_1, \ d(x_q, x_2) = d_2, \ldots, d(x_q, x_n) = d_n")
|
| 36 |
st.write("👉 Usually Euclidean distance is used.")
|
| 37 |
|
| 38 |
+
st.markdown("##### 4️.Sort distances in ascending order")
|
| 39 |
st.write("Example: **d6, d7, d8, ...**")
|
| 40 |
|
| 41 |
+
st.markdown("##### 5️.Pick the K nearest neighbors")
|
| 42 |
st.write("If **K = 3**, choose the 3 nearest points → **x6, x7, x8**")
|
| 43 |
|
| 44 |
+
st.markdown("##### 6️.Check their labels (classes)")
|
| 45 |
st.write("Example: y6, y7, y8")
|
| 46 |
|
| 47 |
+
st.markdown("##### 7️.Perform Majority Voting 🗳️")
|
| 48 |
st.write("The most frequent class among K neighbors becomes the predicted label.")
|
| 49 |
|
| 50 |
st.success("Example: If 2 are Green 🍏 and 1 is Red 🍎 → Query point is predicted as Green 🍏")
|