Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roc curve /part 2 #13022

Open
1 task done
gchinta1 opened this issue May 17, 2024 · 1 comment
Open
1 task done

Roc curve /part 2 #13022

gchinta1 opened this issue May 17, 2024 · 1 comment
Labels
question Further information is requested

Comments

@gchinta1
Copy link

gchinta1 commented May 17, 2024

Search before asking

Question

Hi Glenn , after i run your code still the roc is not good . I tried to use detection confidence maybe that was the problem but nothing the roc is nan. I put the code you gave to me and mayde you can help me again. All the classes are 0 i am using only one. And the last culunm is the confidence one. I am not using ground truth labels only the confidence score. Can you help with modifying for ground truth if it's needs.Thank you
image
image

Additional

`import pandas as pd
from sklearn.metrics import roc_curve, auc
import matplotlib.pyplot as plt
import glob

This will hold all your scores and true values

all_scores = []
y_true = []

Loop through all CSV files in your directory

for csv_file in glob.glob('labelsval1/*.csv'):
data = pd.read_csv(csv_file, header=None)
scores = data[1].tolist()
all_scores.extend(scores)
# Ensure to update y_true based on your actual data specifics, using 0 or 1 accordingly.
y_true.extend([class_label] * len(scores)) # Replace class_label with 0 or 1 as appropriate.

Calculate ROC

fpr, tpr, thresholds = roc_curve(y_true, all_scores)
roc_auc = auc(fpr, tpr)

Plotting

plt.figure()
plt.plot(fpr, tpr, color='darkorange', lw=2, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver Operating Characteristic')
plt.legend(loc="lower right")
plt.show()`

@gchinta1 gchinta1 added the question Further information is requested label May 17, 2024
@glenn-jocher
Copy link
Member

Hello! 🚀 It looks like you're experiencing issues with generating the ROC curve because you're not using ground truth labels.

To properly calculate AUC for ROC, you will need the actual labels (ground truth) for each prediction to compare against. It seems you only have the detection confidence scores.

Here’s a method to modify your script to include ground truth labels:

  1. Update the y_true list in your loop to include actual labels from your dataset.
  2. Map your class labels to 0 or 1 based on the detection (presence or absence of your target class).

Modify this part of your script:

# Assume your actual labels column in CSV is the second column (index 1)
labels = data[1].tolist()  # adjust index based on your data structure
...
y_true.extend(labels)

Ensure you're reading from the correct column index for labels and scores in your CSV. After this adjustment, the ROC calculation should function with accurate class labels.

Hope this helps you move forward! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants