CosmickVisions commited on
Commit
e449ab3
·
verified ·
1 Parent(s): beee103

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -40
app.py CHANGED
@@ -1207,44 +1207,44 @@ elif app_mode == "Predictions":
1207
  except Exception as e:
1208
  st.error(f"Batch prediction failed: {e}")
1209
 
1210
- # Prediction Analysis
1211
- st.subheader("📊 Prediction Analysis")
1212
- if st.checkbox("Analyze Predictions"):
1213
- try:
1214
- y_pred = model.predict(st.session_state.X_test_selected)
1215
- y_test = st.session_state.y_test
1216
 
1217
- if hasattr(model, 'predict'):
1218
- fig, ax = plt.subplots()
1219
- ax.scatter(y_test, y_pred)
1220
- ax.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'k--', lw=2)
1221
- ax.set_xlabel('Actual')
1222
- ax.set_ylabel('Predicted')
1223
- ax.set_title('Actual vs Predicted')
1224
- st.pyplot(fig)
1225
- else:
1226
- conf_matrix = confusion_matrix(y_test, y_pred)
1227
- fig, ax = plt.subplots()
1228
- sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Blues', ax=ax)
1229
- ax.set_xlabel('Predicted Labels')
1230
- ax.set_ylabel('True Labels')
1231
- ax.set_title('Confusion Matrix')
1232
- st.pyplot(fig)
1233
- except Exception as e:
1234
- st.error(f"Prediction analysis failed: {e}")
1235
-
1236
- # Prediction Export
1237
- st.subheader("💾 Export Predictions")
1238
- if st.button("Export Predictions as PDF"):
1239
- try:
1240
- from fpdf import FPDF
1241
- pdf = FPDF()
1242
- pdf.add_page()
1243
- pdf.set_font("Arial", size=12)
1244
- pdf.cell(200, 10, txt="Predictions Report", ln=True, align='C')
1245
- pdf.cell(200, 10, txt=f"Model Type: {type(model).__name__}", ln=True)
1246
- pdf.cell(200, 10, txt=f"Problem Type: {'Regression' if hasattr(model, 'predict') else 'Classification'}", ln=True)
1247
- pdf.output("predictions_report.pdf")
1248
- st.success("Predictions exported successfully!")
1249
- except Exception as e:
1250
- st.error(f"An unexpected error occurred: {e}")
 
1207
  except Exception as e:
1208
  st.error(f"Batch prediction failed: {e}")
1209
 
1210
+ # Prediction Analysis
1211
+ st.subheader("📊 Prediction Analysis")
1212
+ if st.checkbox("Analyze Predictions"):
1213
+ try:
1214
+ y_pred = model.predict(st.session_state.X_test_selected)
1215
+ y_test = st.session_state.y_test
1216
 
1217
+ if hasattr(model, 'predict'):
1218
+ fig, ax = plt.subplots()
1219
+ ax.scatter(y_test, y_pred)
1220
+ ax.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'k--', lw=2)
1221
+ ax.set_xlabel('Actual')
1222
+ ax.set_ylabel('Predicted')
1223
+ ax.set_title('Actual vs Predicted')
1224
+ st.pyplot(fig)
1225
+ else:
1226
+ conf_matrix = confusion_matrix(y_test, y_pred)
1227
+ fig, ax = plt.subplots()
1228
+ sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Blues', ax=ax)
1229
+ ax.set_xlabel('Predicted Labels')
1230
+ ax.set_ylabel('True Labels')
1231
+ ax.set_title('Confusion Matrix')
1232
+ st.pyplot(fig)
1233
+ except Exception as e:
1234
+ st.error(f"Prediction analysis failed: {e}")
1235
+
1236
+ # Prediction Export
1237
+ st.subheader("💾 Export Predictions")
1238
+ if st.button("Export Predictions as PDF"):
1239
+ try:
1240
+ from fpdf import FPDF
1241
+ pdf = FPDF()
1242
+ pdf.add_page()
1243
+ pdf.set_font("Arial", size=12)
1244
+ pdf.cell(200, 10, txt="Predictions Report", ln=True, align='C')
1245
+ pdf.cell(200, 10, txt=f"Model Type: {type(model).__name__}", ln=True)
1246
+ pdf.cell(200, 10, txt=f"Problem Type: {'Regression' if hasattr(model, 'predict') else 'Classification'}", ln=True)
1247
+ pdf.output("predictions_report.pdf")
1248
+ st.success("Predictions exported successfully!")
1249
+ except Exception as e:
1250
+ st.error(f"An unexpected error occurred: {e}")