Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,7 +61,7 @@ def process_and_evaluate(df):
|
|
| 61 |
plt.savefig('roc_curve.png') # Save the ROC curve as an image
|
| 62 |
plt.close() # Close the plot to free memory
|
| 63 |
|
| 64 |
-
return classification_rep, 'correlation_matrix.png', 'roc_curve.png'
|
| 65 |
|
| 66 |
# Create the Streamlit app
|
| 67 |
st.set_page_config(page_title="心臟病預測系統")
|
|
@@ -72,14 +72,28 @@ st.write("上傳包含心臟病數據的 CSV 文件以獲取分類報告、相
|
|
| 72 |
uploaded_file = st.file_uploader("上傳 CSV 文件", type="csv")
|
| 73 |
|
| 74 |
if uploaded_file is not None:
|
| 75 |
-
# Load the dataset
|
| 76 |
df = pd.read_csv(uploaded_file)
|
| 77 |
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
st.subheader("分類報告")
|
| 81 |
st.text_area("分類報告", classification_report, height=400)
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
st.subheader("相依矩陣")
|
| 84 |
st.image(correlation_matrix_path)
|
| 85 |
|
|
|
|
| 61 |
plt.savefig('roc_curve.png') # Save the ROC curve as an image
|
| 62 |
plt.close() # Close the plot to free memory
|
| 63 |
|
| 64 |
+
return classification_rep, conf_matrix, 'correlation_matrix.png', 'roc_curve.png'
|
| 65 |
|
| 66 |
# Create the Streamlit app
|
| 67 |
st.set_page_config(page_title="心臟病預測系統")
|
|
|
|
| 72 |
uploaded_file = st.file_uploader("上傳 CSV 文件", type="csv")
|
| 73 |
|
| 74 |
if uploaded_file is not None:
|
| 75 |
+
# Load the dataset directly from the uploaded file
|
| 76 |
df = pd.read_csv(uploaded_file)
|
| 77 |
|
| 78 |
+
# Process the data and generate reports
|
| 79 |
+
classification_report, conf_matrix, correlation_matrix_path, roc_curve_path = process_and_evaluate(df)
|
| 80 |
|
| 81 |
st.subheader("分類報告")
|
| 82 |
st.text_area("分類報告", classification_report, height=400)
|
| 83 |
|
| 84 |
+
st.subheader("混淆矩陣")
|
| 85 |
+
st.write(conf_matrix)
|
| 86 |
+
|
| 87 |
+
# Plot and display the confusion matrix
|
| 88 |
+
plt.figure(figsize=(8, 6))
|
| 89 |
+
sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Blues', xticklabels=['Negative', 'Positive'], yticklabels=['Negative', 'Positive'])
|
| 90 |
+
plt.ylabel('實際值')
|
| 91 |
+
plt.xlabel('預測值')
|
| 92 |
+
plt.title('混淆矩陣')
|
| 93 |
+
plt.savefig('confusion_matrix.png') # Save the confusion matrix as an image
|
| 94 |
+
plt.close() # Close the plot to free memory
|
| 95 |
+
st.image('confusion_matrix.png')
|
| 96 |
+
|
| 97 |
st.subheader("相依矩陣")
|
| 98 |
st.image(correlation_matrix_path)
|
| 99 |
|