Spaces:
Runtime error
Runtime error
Commit
·
bdc6991
1
Parent(s):
0b5bb62
upload test
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from matplotlib import pyplot as plt
|
|
| 9 |
import seaborn as sns
|
| 10 |
import gradio as gr
|
| 11 |
import numpy as np
|
| 12 |
-
|
| 13 |
|
| 14 |
missing_values = ["--"]
|
| 15 |
data = pd.read_csv('./macau_weather.csv', na_values = missing_values)
|
|
@@ -65,6 +65,14 @@ def make_r_plot(libraries, sd,cd,dd,ld,rc,rd,rl,rn,rf):
|
|
| 65 |
plt.xlabel("No. Cross Validation")
|
| 66 |
return fig
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
table_data, clean_data = make_ra_table(data)
|
| 69 |
|
| 70 |
morning_features = ['air_pressure', 'aver_tem', 'humidity',
|
|
@@ -72,7 +80,13 @@ morning_features = ['air_pressure', 'aver_tem', 'humidity',
|
|
| 72 |
feature=clean_data[morning_features].copy()
|
| 73 |
label = clean_data['rain_accum'].copy()
|
| 74 |
X_train,X_test,y_train,y_test = train_test_split(feature,label,test_size=0.33,random_state=324)
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
if __name__ == '__main__':
|
| 78 |
with gr.Blocks() as demo:
|
|
@@ -134,7 +148,23 @@ if __name__ == '__main__':
|
|
| 134 |
rl=gr.Slider(label="min_samples_leaf of RandomForest", value=10, minimum=1, maximum=50, step=5)
|
| 135 |
rn = gr.Slider(label="n_estimators of RandomForest", value=11, minimum=5, maximum=15, step=1)
|
| 136 |
rf =gr.Slider(label="max_features of RandomForest", value=20,minimun=5, maximum=30, step=1)
|
| 137 |
-
|
|
|
|
| 138 |
train.click(fn=make_r_plot, inputs=[libraries,sd,cd,dd,ld,rc,rd,rl,rn,rf], outputs=gr.Plot(label = "Vaildation Score Plot"))
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
import seaborn as sns
|
| 10 |
import gradio as gr
|
| 11 |
import numpy as np
|
| 12 |
+
import joblib
|
| 13 |
|
| 14 |
missing_values = ["--"]
|
| 15 |
data = pd.read_csv('./macau_weather.csv', na_values = missing_values)
|
|
|
|
| 65 |
plt.xlabel("No. Cross Validation")
|
| 66 |
return fig
|
| 67 |
|
| 68 |
+
def download_clf():
|
| 69 |
+
joblib.dump(clf,"dtc_model.m")
|
| 70 |
+
return "./dtc_model.m"
|
| 71 |
+
|
| 72 |
+
def download_rfc():
|
| 73 |
+
joblib.dump(rfc,"rfc_model.m")
|
| 74 |
+
return "./rfc_model.m"
|
| 75 |
+
|
| 76 |
table_data, clean_data = make_ra_table(data)
|
| 77 |
|
| 78 |
morning_features = ['air_pressure', 'aver_tem', 'humidity',
|
|
|
|
| 80 |
feature=clean_data[morning_features].copy()
|
| 81 |
label = clean_data['rain_accum'].copy()
|
| 82 |
X_train,X_test,y_train,y_test = train_test_split(feature,label,test_size=0.33,random_state=324)
|
| 83 |
+
clf = DecisionTreeClassifier(random_state=25)
|
| 84 |
+
rfc = RandomForestClassifier(random_state=25, n_estimators=11)
|
| 85 |
+
clf.fit(X_train,y_train)
|
| 86 |
+
rfc.fit(X_train,y_train)
|
| 87 |
+
clf_score = clf.score(X_test, y_test)
|
| 88 |
+
rfc_score = rfc.score(X_test, y_test)
|
| 89 |
+
score = pd.DataFrame([[clf_score,rfc_score],['DecisioTree Score','RandomForest Score']],columns=['DecisioTree Score','RandomForest Score'])
|
| 90 |
|
| 91 |
if __name__ == '__main__':
|
| 92 |
with gr.Blocks() as demo:
|
|
|
|
| 148 |
rl=gr.Slider(label="min_samples_leaf of RandomForest", value=10, minimum=1, maximum=50, step=5)
|
| 149 |
rn = gr.Slider(label="n_estimators of RandomForest", value=11, minimum=5, maximum=15, step=1)
|
| 150 |
rf =gr.Slider(label="max_features of RandomForest", value=20,minimun=5, maximum=30, step=1)
|
| 151 |
+
with gr.Row():
|
| 152 |
+
train = gr.Button(value="Train")
|
| 153 |
train.click(fn=make_r_plot, inputs=[libraries,sd,cd,dd,ld,rc,rd,rl,rn,rf], outputs=gr.Plot(label = "Vaildation Score Plot"))
|
| 154 |
+
gr.Markdown("""
|
| 155 |
+
## Testing:
|
| 156 |
+
There are the final testing scores
|
| 157 |
+
""")
|
| 158 |
+
with gr.Row():
|
| 159 |
+
demo.load(fn=make_clf_t_plot, inputs=None, outputs=gr.Plot(label = "Final Score"))
|
| 160 |
+
gr.Markdown("""
|
| 161 |
+
## Download Model:
|
| 162 |
+
""")
|
| 163 |
+
with gr.Row():
|
| 164 |
+
with gr.Column():
|
| 165 |
+
clf_model = gr.Button(value="Download DecisionTree Model")
|
| 166 |
+
clf_model.click(fn=download_clf, inputs=None, outputs=gr.File(label="DecisionTree Model"))
|
| 167 |
+
with gr.Column():
|
| 168 |
+
rfc_model = gr.Button(value="Download RandomForest Model")
|
| 169 |
+
rfc_model.click(fn=download_rfc, inputs=None, outputs=gr.File(label="RandomForest Model"))
|
| 170 |
+
demo.launch()
|