0
$\begingroup$

I am using logistic regression to predict df['MortSubiteCardiaque'], which contains 0 and 1, based on my continuous variable df['NTProBNP']. I would like to determine the threshold for df['NTProBNP'], specifically the minimum value of df['NTProBNP'] that predicts 1. How can I do that?

  df['constante'] = 1

  X = df[['constante', 'NTProBNP']]
 y = df['MortSubiteCardiaque']

 model = sm.Logit(y, X)
 result = model.fit()

 y_probs = result.predict(X)

 fpr, tpr, thresholds = roc_curve(y, y_probs)

 roc_auc = auc(fpr, tpr)
 # optimal cut-off point 
 optimal_idx = np.argmax(tpr - fpr)
optimal_threshold = thresholds[optimal_idx]


# i had 2361 with this line 
df['NTProBNP'][y_probs >= optimal_threshold].min()
$\endgroup$
2
  • $\begingroup$ Is the scale of NTProBNP such that higher values correspond more to MortSubiteCardiaque = 1? $\endgroup$
    – m13op22
    Feb 12 at 16:09
  • $\begingroup$ #@m13op22 yes, mean 5116.904762 std 6759.119454 min 15.000000 25% 737.250000 50% 2463.500000 75% 5514.250000 max 25000.000000 I think I can find the solution by inverting the logistic function, setting it equal to the optimal threshold. This solution seems logical to me, but I can't find a reference. $\endgroup$ Feb 13 at 8:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.