https://rpubs.com/tmartens/classification_metrics

re: RPubs - Classification Metrics using R

The get.rocPlot.auc function gives an error. I have found similar error messages in this type of code.
Can you help? Thank you. Mary A. Marion

Here is a code extract. This is what the error message is referring to.
for (i in threshold.grid) {

  •     yhat = as.numeric(df$prob>i)
    
  •     predicted = cbind(df$predicted,yhat)
    
  • }
  • for (j in 1:length(threshold.grid)){
  •     class.factor = factor(df$actual,levels = c(0,1))
    
  •     predicted.factor = factor(predicted[,j], levels = c(0,1))
    
  •     t = table(class.factor, predicted.factor)
    
  •     sensitivity = t[2,2] / (t[2,2] + t[2,1])
    
  •     specificity = t[1,1] / (t[1,1] + t[1,2])
    
  •     y[j] = sensitivity
    
  •     x[j] = 1 - specificity
    

get.rocPlot.auc(report2)
Error in predicted[, j] : subscript out of bounds

What is report2?

get.rocPlot.auc(preds)

report2 consists of a data frame with 2 columns labelled actual and predicted. These refer to the actual classifications of validation set and the predicted classifications of validation set.

This worked for me with get.rocPlot.auc(preds)

Where did you find the data set preds? I could not find it.

Isn't it the object of the read statement?

I don't have the excel csv data set. Do you know how where it is?

I needed to change the input dataset to report.3 which contained columns actual, pred.class, and the prob associated with the predicted class.

actual,pred.class,prob = apply(pred.prob,1,max))

Same error? It is my data.

preds = read.csv('classification-output-data.csv', sep=',', header = TRUE)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.