VJyzCELERY
commited on
Commit
·
f7df087
1
Parent(s):
65f7e0a
Improved Code Scalability
Browse files- app.py +5 -10
- component.py +10 -43
app.py
CHANGED
|
@@ -601,26 +601,21 @@ classifier.fit(
|
|
| 601 |
)
|
| 602 |
""")
|
| 603 |
history = model.text_based_recommender.history
|
|
|
|
| 604 |
|
| 605 |
-
|
| 606 |
-
h2('Result Training Loss and Error')
|
| 607 |
results = {
|
| 608 |
"merror": history['validation_0']['merror'],
|
| 609 |
"mlogloss": history['validation_0']['mlogloss']
|
| 610 |
}
|
| 611 |
plot_output = gr.Plot(format='png')
|
| 612 |
btn = gr.Button("Generate Plot")
|
| 613 |
-
btn.click(fn=lambda:plot_training_results(
|
| 614 |
|
| 615 |
-
h2('
|
| 616 |
-
|
| 617 |
-
resultsval = {
|
| 618 |
-
"merror": history['validation_1']['merror'],
|
| 619 |
-
"mlogloss": history['validation_1']['mlogloss']
|
| 620 |
-
}
|
| 621 |
plot_outputval = gr.Plot(format='png')
|
| 622 |
btnval = gr.Button("Generate Plot")
|
| 623 |
-
btnval.click(fn=lambda:plot_training_results(
|
| 624 |
y_pred = model.text_based_recommender.classifier.predict(vectorizer.transform(test_df['cleaned_review']))
|
| 625 |
y_test = model.text_based_recommender.app_id_encoder.transform(test_df['app_id'])
|
| 626 |
class_report = classification_report(y_test,y_pred)
|
|
|
|
| 601 |
)
|
| 602 |
""")
|
| 603 |
history = model.text_based_recommender.history
|
| 604 |
+
n_estimator = len(history['validation_0']['merror'])
|
| 605 |
|
| 606 |
+
h2('Training vs Validation log loss')
|
|
|
|
| 607 |
results = {
|
| 608 |
"merror": history['validation_0']['merror'],
|
| 609 |
"mlogloss": history['validation_0']['mlogloss']
|
| 610 |
}
|
| 611 |
plot_output = gr.Plot(format='png')
|
| 612 |
btn = gr.Button("Generate Plot")
|
| 613 |
+
btn.click(fn=lambda:plot_training_results(n_estimator,history['validation_0']['mlogloss'],history['validation_1']['mlogloss'],'Training Log Loss','Validation Log Loss','Log Loss','N Estimator'), inputs=[], outputs=plot_output, preprocess=False)
|
| 614 |
|
| 615 |
+
h2('Training vs Validation error')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 616 |
plot_outputval = gr.Plot(format='png')
|
| 617 |
btnval = gr.Button("Generate Plot")
|
| 618 |
+
btnval.click(fn=lambda:plot_training_results(n_estimator,history['validation_0']['merror'],history['validation_1']['merror'],'Training error','Validation error','merror','N Estimator'), inputs=[], outputs=plot_outputval, preprocess=False)
|
| 619 |
y_pred = model.text_based_recommender.classifier.predict(vectorizer.transform(test_df['cleaned_review']))
|
| 620 |
y_test = model.text_based_recommender.app_id_encoder.transform(test_df['app_id'])
|
| 621 |
class_report = classification_report(y_test,y_pred)
|
component.py
CHANGED
|
@@ -144,51 +144,18 @@ def code_cell(code):
|
|
| 144 |
gr.Code(inspect.cleandoc(code), language='python')
|
| 145 |
|
| 146 |
## This for EDA, Preprocess, and training
|
| 147 |
-
def plot_training_results(
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
This function generates a line plot that visualizes the model's training
|
| 152 |
-
performance over time (e.g., across epochs or folds), using the merror
|
| 153 |
-
(training error) and mlogloss (log loss) values.
|
| 154 |
-
|
| 155 |
-
Args:
|
| 156 |
-
results (dict): A dictionary containing two keys:
|
| 157 |
-
- 'merror': list of training error values.
|
| 158 |
-
- 'mlogloss': list of log loss values.
|
| 159 |
-
Example:
|
| 160 |
-
{
|
| 161 |
-
"merror": [0.12, 0.10, 0.08],
|
| 162 |
-
"mlogloss": [0.35, 0.32, 0.30]
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
Returns:
|
| 166 |
-
matplotlib.figure.Figure: A Matplotlib figure showing the trends of
|
| 167 |
-
training error and log loss as line plots.
|
| 168 |
-
|
| 169 |
-
Example:
|
| 170 |
-
results = {
|
| 171 |
-
"merror": [0.12, 0.10, 0.08],
|
| 172 |
-
"mlogloss": [0.35, 0.32, 0.30]
|
| 173 |
-
}
|
| 174 |
-
plot_output = gr.Plot()
|
| 175 |
-
btn = gr.Button("Generate Plot")
|
| 176 |
-
btn.click(fn=lambda:plot_training_results(results), inputs=[], outputs=plot_output, preprocess=False)
|
| 177 |
-
"""
|
| 178 |
-
epochs = list(range(1, len(results["merror"]) + 1))
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
| 183 |
|
| 184 |
-
|
| 185 |
-
plt.xlabel('Epoch / Fold')
|
| 186 |
-
plt.ylabel('Value')
|
| 187 |
-
plt.legend()
|
| 188 |
-
plt.grid(True)
|
| 189 |
-
plt.tight_layout()
|
| 190 |
-
|
| 191 |
-
return plt.gcf()
|
| 192 |
|
| 193 |
# for Recommendation section
|
| 194 |
def input_name_textbox(Label:str, Placeholder:str):
|
|
|
|
| 144 |
gr.Code(inspect.cleandoc(code), language='python')
|
| 145 |
|
| 146 |
## This for EDA, Preprocess, and training
|
| 147 |
+
def plot_training_results(x,y1,y2,y1label,y2label,ylabel,xlabel,title=""):
|
| 148 |
+
fig,ax=plt.subplots(figsize=(8,5))
|
| 149 |
+
ax.plot(x, y1, marker='o', label=y1label, color='blue')
|
| 150 |
+
ax.plot(x, y2, marker='s', label=y2label, color='orange')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
ax.set_title(title)
|
| 153 |
+
ax.set_xlabel(xlabel=xlabel)
|
| 154 |
+
ax.set_ylabel(ylabel=ylabel)
|
| 155 |
+
ax.legend()
|
| 156 |
+
ax.grid(True)
|
| 157 |
|
| 158 |
+
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
# for Recommendation section
|
| 161 |
def input_name_textbox(Label:str, Placeholder:str):
|