Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import numpy as np
|
2 |
import gradio as gr
|
3 |
|
|
|
4 |
def homework01_solution1(K, X1, X2):
|
5 |
|
6 |
K = int(K)
|
@@ -26,19 +27,23 @@ def homework01_solution1(K, X1, X2):
|
|
26 |
|
27 |
for i in range(K):
|
28 |
idx = nb_indice[0][i]
|
29 |
-
fea = X[idx]
|
|
|
|
|
30 |
dist = nb_dist[0][i]
|
31 |
label = y[idx]
|
32 |
|
33 |
#print(idx, fea, dist, label)
|
34 |
|
35 |
# Dictionary to append
|
36 |
-
new_data = {'Rank of closest neighbor': idx, 'Features (X_1,X_2)':fea, 'Label (Y)':label , 'Distance to query data': dist}
|
37 |
-
|
38 |
# Append dictionary to DataFrame
|
39 |
-
|
|
|
40 |
|
41 |
results = results.sort_values(by='Rank of closest neighbor')
|
|
|
42 |
|
43 |
return results, predicted_label
|
44 |
|
|
|
1 |
import numpy as np
|
2 |
import gradio as gr
|
3 |
|
4 |
+
|
5 |
def homework01_solution1(K, X1, X2):
|
6 |
|
7 |
K = int(K)
|
|
|
27 |
|
28 |
for i in range(K):
|
29 |
idx = nb_indice[0][i]
|
30 |
+
fea = X[idx].tolist()
|
31 |
+
fea = '({})'.format(', '.join(map(str, fea)))
|
32 |
+
|
33 |
dist = nb_dist[0][i]
|
34 |
label = y[idx]
|
35 |
|
36 |
#print(idx, fea, dist, label)
|
37 |
|
38 |
# Dictionary to append
|
39 |
+
new_data = {'Rank of closest neighbor': idx, 'Features (X_1,X_2)': fea, 'Label (Y)':label , 'Distance to query data': dist}
|
40 |
+
tmp = pd.DataFrame(new_data, index=[0])
|
41 |
# Append dictionary to DataFrame
|
42 |
+
#data = data.append(new_data, ignore_index=True)
|
43 |
+
results = pd.concat([results, tmp], ignore_index=True)
|
44 |
|
45 |
results = results.sort_values(by='Rank of closest neighbor')
|
46 |
+
results
|
47 |
|
48 |
return results, predicted_label
|
49 |
|