0

During the model evaluation phase, I observed that my model predicted values in the range of 30.309 - 59.556.

I wanted to set a threshold so that I can say the values greater than that threshold are correct else incorrect.

I set the different threshold as:

start, stop, step = min(y_pred), max(y_pred)+1, (max(y_pred) - min(y_pred))/10

for i in arange(start, stop, step):
    k.append(round(i, 2))

This provides me 10 different equally spaced threshold as follows:

Thresholds: [30.31, 33.23, 36.16, 39.08, 42.01, 44.93, 47.86, 50.78, 53.71, 56.63, 59.56]

I performed the model evaluation on these thresholds and the results are as follows:

Sensitivity: [1.0, 0.999, 0.983, 0.866, 0.497, 0.197, 0.093, 0.036, 0.007, 0.0, 0.0]
Specificity: [0.0, 0.0, 0.003, 0.027, 0.172, 0.576, 0.845, 0.915, 0.971, 0.997, 1.0]

The sensitivity goes from 1 to 0, where specificity from 0 to 1.

I plot them and the results are as follows:

fig = plt.figure(facecolor='white', figsize=(18, 4))
plt.title("Sensitivity vs Specificiy")
plt.plot(sensitivity, c='red')
plt.plot(specificity, c='Green')
plt.legend(['Sensitivity','Specificity'])
plt.grid(True)
plt.show()

enter image description here

But I want the x-axis should show the threshold instead of numbers from 0 to 10.

I tried to set the xticks but results are as follows:

fig = plt.figure(facecolor='white', figsize=(18, 4))
plt.title("Sensitivity vs Specificiy")
plt.plot(sensitivity, c='red')
plt.plot(specificity, c='Green')
plt.legend(['Sensitivity','Specificity'])
**plt.xticks(k)**
plt.grid(True)
plt.show()

enter image description here Where I am making the mistake?

Ali R. Memon
  • 121
  • 1
  • 1
  • 12

1 Answers1

1

Instead of plotting sensitivity and specificity as 1D plots, you can plot them against thresholds as 2D plots. Just add it as x axis to your plots.

fig = plt.figure(facecolor='white', figsize=(18, 4))
plt.title("Sensitivity vs Specificiy")
plt.plot(thresholds, sensitivity, c='red')
plt.plot(thresholds, specificity, c='Green')
plt.legend(['Sensitivity','Specificity'])
plt.grid(True)
plt.show()

The results is below. enter image description here

ilke444
  • 2,641
  • 1
  • 17
  • 31