Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,34 +33,27 @@ def predict_strength(cement, blast_furnace_slag, fly_ash, water, superplasticize
|
|
| 33 |
prediction = ebm.predict(last_input_data_scaled)
|
| 34 |
return prediction[0]
|
| 35 |
|
| 36 |
-
# Explanation function for detailed report and enhanced visual
|
| 37 |
def show_local_explanation():
|
| 38 |
if last_input_data_scaled is not None:
|
| 39 |
local_exp = ebm.explain_local(last_input_data_scaled)
|
| 40 |
contributions = local_exp.data(0)['scores']
|
| 41 |
names = local_exp.data(0)['names']
|
| 42 |
|
| 43 |
-
# Generate user-friendly text report based on contributions
|
| 44 |
report_lines = []
|
| 45 |
for name, contribution in zip(names, contributions):
|
|
|
|
| 46 |
if contribution > 0:
|
| 47 |
-
if
|
| 48 |
-
report_lines.append(f"-
|
| 49 |
-
|
| 50 |
-
report_lines.append(f"-
|
| 51 |
-
elif name == "fly_ash":
|
| 52 |
-
report_lines.append(f"- Fly Ash has a minor positive effect on strength (+{contribution:.2f}).")
|
| 53 |
-
elif name == "age":
|
| 54 |
-
report_lines.append(f"- Age has a strong positive effect, as concrete generally strengthens with time (+{contribution:.2f}).")
|
| 55 |
elif contribution < 0:
|
| 56 |
-
if
|
| 57 |
-
report_lines.append(f"-
|
| 58 |
-
|
| 59 |
-
report_lines.append(f"-
|
| 60 |
-
elif name == "coarse_aggregate":
|
| 61 |
-
report_lines.append(f"- Coarse Aggregate has a moderate negative effect on strength in this composition ({contribution:.2f}).")
|
| 62 |
-
elif name == "fine_aggregate":
|
| 63 |
-
report_lines.append(f"- Fine Aggregate reduces strength in this mix, suggesting it may need adjustment ({contribution:.2f}).")
|
| 64 |
|
| 65 |
# Join lines into a single report
|
| 66 |
report = "\n".join(report_lines)
|
|
|
|
| 33 |
prediction = ebm.predict(last_input_data_scaled)
|
| 34 |
return prediction[0]
|
| 35 |
|
| 36 |
+
# Explanation function for dynamic detailed report and enhanced visual
|
| 37 |
def show_local_explanation():
|
| 38 |
if last_input_data_scaled is not None:
|
| 39 |
local_exp = ebm.explain_local(last_input_data_scaled)
|
| 40 |
contributions = local_exp.data(0)['scores']
|
| 41 |
names = local_exp.data(0)['names']
|
| 42 |
|
| 43 |
+
# Generate dynamic, user-friendly text report based on contributions
|
| 44 |
report_lines = []
|
| 45 |
for name, contribution in zip(names, contributions):
|
| 46 |
+
abs_contribution = abs(contribution)
|
| 47 |
if contribution > 0:
|
| 48 |
+
if abs_contribution > 10:
|
| 49 |
+
report_lines.append(f"- {name.capitalize()} strongly contributes to concrete strength (+{contribution:.2f}).")
|
| 50 |
+
else:
|
| 51 |
+
report_lines.append(f"- {name.capitalize()} has a minor positive effect on concrete strength (+{contribution:.2f}).")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
elif contribution < 0:
|
| 53 |
+
if abs_contribution > 10:
|
| 54 |
+
report_lines.append(f"- {name.capitalize()} significantly reduces concrete strength ({contribution:.2f}). Consider adjusting this component.")
|
| 55 |
+
else:
|
| 56 |
+
report_lines.append(f"- {name.capitalize()} has a slight negative effect on concrete strength ({contribution:.2f}).")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# Join lines into a single report
|
| 59 |
report = "\n".join(report_lines)
|