Hi,

The plot between Sensitivity and Specificity can help you out here

For the following code

```
dat1 <- data.frame(val=c(1,2,-1,1,2,3),label=c(1,0,1,0,0,0))
pred <- prediction(dat1$val,dat1$label)
perf = performance(pred,measure="tpr",x.measure="fpr")
plot(perf)
```

We have the following graph. This is essentially Sensitivity vs (1- Specificity )

Now, in order to find the most optimal binning, we need to find the point that is closes to (0,1) in the graph ( Euclidean distance ). I have written a small script that will find out this value

```
dist <- 100
alphaNumber <- 0
for(i in 1:length(perf@x.values[[1]]))
{
xVal <- perf@x.values[[1]][i]
yVal <- perf@y.values[[1]][i]
if(is.infinite(xVal) && xVal < 0)
{
xVal <- 0
}
if(is.infinite(xVal) && xVal > 0)
{
xVal <- 1
}
if(is.infinite(yVal) && yVal < 0)
{
yVal <- 0
}
if(is.infinite(yVal) && yVal > 0)
{
yVal <- 1
}
dist1 <- ((xVal -0)^2 + (yVal -1)^2)^0.5
print(dist1)
print(xVal)
print(yVal)
if(dist1 < dist)
{
alphaNumber <- i
dist <- dist1
}
}
print(perf@alpha.values[[1]][alphaNumber])
```

I tried it on the ROCR,Simple dataset which has the following graph

The value that came out was

```
> print(perf@alpha.values[[1]][alphaNumber])
[1] 0.5014893
```

Let me know if this helps