File size: 1,513 Bytes
fe4357e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import streamlit as st
from sklearn.metrics import roc_curve, auc
import numpy as np
import matplotlib.pyplot as plt

# Streamlit app
st.title("ROC Paper Seizure")

st.write("""
This application allows you to upload a CSV file containing true labels and predicted scores.
It computes the Receiver Operating Characteristic (ROC) curve and the Area Under the Curve (AUC).
""")

# Upload file
uploaded_file = st.file_uploader("Upload your data (CSV with 'true_labels' and 'scores' columns)", type=["csv"])

if uploaded_file:
    try:
        # Load CSV file
        data = np.genfromtxt(uploaded_file, delimiter=',', names=True)
        true_labels = data['true_labels']
        scores = data['scores']

        # Compute ROC curve and AUC
        fpr, tpr, thresholds = roc_curve(true_labels, scores)
        roc_auc = auc(fpr, tpr)

        # Display AUC value
        st.write(f"**AUC (Area Under the Curve):** {roc_auc:.3f}")

        # Plot ROC curve
        fig, ax = plt.subplots()
        ax.plot(fpr, tpr, color='blue', lw=2, label=f"ROC curve (AUC = {roc_auc:.2f})")
        ax.plot([0, 1], [0, 1], color='gray', linestyle='--', lw=2)
        ax.set_xlim([0.0, 1.0])
        ax.set_ylim([0.0, 1.05])
        ax.set_xlabel('False Positive Rate')
        ax.set_ylabel('True Positive Rate')
        ax.set_title('Receiver Operating Characteristic')
        ax.legend(loc="lower right")

        st.pyplot(fig)

    except Exception as e:
        st.error(f"An error occurred while processing the file: {e}")