Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,6 +28,12 @@ def homework01_solution1(K, X1, X2):
|
|
28 |
pred = neigh.predict(X)
|
29 |
squared_error = (pred-y)**2
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
train_data['Predicted Label ('+str(K)+'-NN)'] = pred
|
32 |
train_data['Squaredd Error'] = squared_error
|
33 |
train_data['Predicted Label ('+str(K)+'-NN)'] = train_data['Predicted Label ('+str(K)+'-NN)'].round(3)
|
@@ -62,7 +68,7 @@ def homework01_solution1(K, X1, X2):
|
|
62 |
results = results.sort_values(by='Rank of closest neighbor')
|
63 |
results['Distance to query data'] = results['Distance to query data'].round(3)
|
64 |
|
65 |
-
return train_data, results, predicted_label
|
66 |
|
67 |
|
68 |
|
@@ -76,11 +82,12 @@ set_X2 = gr.Number(value=2)
|
|
76 |
set_output_traindata = gr.Dataframe(type='pandas', label ='Train Dataset')
|
77 |
set_output_q1a = gr.Dataframe(type='pandas', label ='Question 1: KNN-Regressor Search')
|
78 |
set_output_q1b = gr.Textbox(label ='Question 1: KNN-Regressor Prediction')
|
|
|
79 |
|
80 |
### configure Gradio
|
81 |
interface = gr.Interface(fn=homework01_solution1,
|
82 |
inputs=[set_K, set_X1, set_X2],
|
83 |
-
outputs=[set_output_traindata, set_output_q1a, set_output_q1b],
|
84 |
|
85 |
title="CSCI4750/5750(hw01-PartI): Mathematics for KNN (Question 1: KNN-Regressor Search)",
|
86 |
description= "Click examples below for a quick demo",
|
|
|
28 |
pred = neigh.predict(X)
|
29 |
squared_error = (pred-y)**2
|
30 |
|
31 |
+
#(Q2.3) evaluate mean squared error
|
32 |
+
import sklearn
|
33 |
+
y_pred = neigh.predict(X)
|
34 |
+
mse = sklearn.metrics.mean_squared_error(y,y_pred)
|
35 |
+
|
36 |
+
|
37 |
train_data['Predicted Label ('+str(K)+'-NN)'] = pred
|
38 |
train_data['Squaredd Error'] = squared_error
|
39 |
train_data['Predicted Label ('+str(K)+'-NN)'] = train_data['Predicted Label ('+str(K)+'-NN)'].round(3)
|
|
|
68 |
results = results.sort_values(by='Rank of closest neighbor')
|
69 |
results['Distance to query data'] = results['Distance to query data'].round(3)
|
70 |
|
71 |
+
return train_data, results, predicted_label, mse
|
72 |
|
73 |
|
74 |
|
|
|
82 |
set_output_traindata = gr.Dataframe(type='pandas', label ='Train Dataset')
|
83 |
set_output_q1a = gr.Dataframe(type='pandas', label ='Question 1: KNN-Regressor Search')
|
84 |
set_output_q1b = gr.Textbox(label ='Question 1: KNN-Regressor Prediction')
|
85 |
+
set_output_q3 = gr.Textbox(label ='Question 3: KNN-Regressor MSE (Training data)')
|
86 |
|
87 |
### configure Gradio
|
88 |
interface = gr.Interface(fn=homework01_solution1,
|
89 |
inputs=[set_K, set_X1, set_X2],
|
90 |
+
outputs=[set_output_traindata, set_output_q1a, set_output_q1b, set_output_q3],
|
91 |
|
92 |
title="CSCI4750/5750(hw01-PartI): Mathematics for KNN (Question 1: KNN-Regressor Search)",
|
93 |
description= "Click examples below for a quick demo",
|