nn commited on
Commit
2130ef6
·
verified ·
1 Parent(s): f55ad79

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -4,7 +4,7 @@ import torch
4
  import shap
5
  import matplotlib.pyplot as plt
6
  import joblib
7
-
8
  # Load scalers and model
9
  @st.cache_resource
10
  def load_resources():
@@ -54,7 +54,7 @@ with torch.no_grad():
54
  prediction = model(torch.tensor(input_scaled, dtype=torch.float32)).numpy()
55
  prediction_unscaled = scaler_y.inverse_transform(prediction)
56
 
57
- st.write(f"Predicted Resilience Modulus: {prediction_unscaled[0][0]:.2f}")
58
 
59
  # SHAP explanation
60
  if st.button("Explain Prediction"):
@@ -81,9 +81,12 @@ if st.button("Explain Prediction"):
81
  shap.plots.waterfall(explanation, show=False)
82
  st.pyplot(fig)
83
 
84
- st.write(f"Base value (unscaled): {([[expected_value]])[0][0]:.4f}")
85
- st.write(f"Output value (unscaled): {prediction_unscaled[0][0]:.4f}")
86
 
87
  st.write("\nFeature contributions (unscaled):")
88
- for name, value in zip(feature_names, shap_values_single):
89
- st.write(f"{name}: {value:.4f}")
 
 
 
 
4
  import shap
5
  import matplotlib.pyplot as plt
6
  import joblib
7
+ import pandas as pd
8
  # Load scalers and model
9
  @st.cache_resource
10
  def load_resources():
 
54
  prediction = model(torch.tensor(input_scaled, dtype=torch.float32)).numpy()
55
  prediction_unscaled = scaler_y.inverse_transform(prediction)
56
 
57
+ st.write(f"Predicted Resilience Modulus: {prediction_unscaled[0][0]:.2f} MPa")
58
 
59
  # SHAP explanation
60
  if st.button("Explain Prediction"):
 
81
  shap.plots.waterfall(explanation, show=False)
82
  st.pyplot(fig)
83
 
84
+ st.write(f"Base value (unscaled): {([[expected_value]])[0][0]:.2f} MPa")
85
+ st.write(f"Output value (unscaled): {prediction_unscaled[0][0]:.2f} MPa")
86
 
87
  st.write("\nFeature contributions (unscaled):")
88
+ feature_contributions = pd.DataFrame({
89
+ 'Contribution': shap_values_single
90
+ }, index=feature_names)
91
+ feature_contributions['Contribution'] = feature_contributions['Contribution'].round(4)
92
+ st.table(feature_contributions)