Find AUC with tree package - binary response

354 views Asked by At

Attempting to get ROC Curve and AUC for CART decision tree which was made using "tree" package.

> str(pruned.tree7)

Here is the Structure of my tree

'data.frame': 13 obs. of 6 variables:

$ var : Factor w/ 15 levels "","Age",..: 15 10 1 11 11 5 1 1 15 1 ...

$ n : num 383 158 29 129 110 38 20 18 72 7 ...

$ dev : num 461.1 218.6 29.6 174 141.8 ...

$ yval : Factor w/ 2 levels "Negative","Positive": 2 2 1 2 2 1 2 1 2 1 ...

$ splits: chr [1:13, 1:2] "<19.5" "<81.5" "" "<65" ...

..- attr(*, "dimnames")=List of 2

.. ..$ : NULL

.. ..$ : chr "cutleft" "cutright"

$ yprob : num [1:13, 1:2] 0.29 0.475 0.793 0.403 0.345 ...

..- attr(*, "dimnames")=List of 2

.. ..$ : NULL

.. ..$ : chr "Negative" "Positive"

Referencing the above structure, I have written (many variations of) the following code:

> preds <- prediction(pruned.tree7$frame$yprob, dimnames(pruned.tree7$frame$yprob))

Error in prediction(pruned.tree7$frame$yprob, dimnames(pruned.tree7$frame$yprob)) : Number of predictions in each run must be equal to the number of labels for each run.

> preds <- prediction(pruned.tree7$frame$yprob, dimnames)

Error in prediction(pruned.tree7$frame$yprob, dimnames) : Format of labels is invalid.

> preds <- prediction(pruned.tree7$frame$yprob, "dimnames")

Error in prediction(pruned.tree7$frame$yprob, "dimnames") : Number of cross-validation runs must be equal for predictions and labels.

> preds <- prediction(pruned.tree7$frame$yprob, names(yprob))

Error in is.data.frame(labels) : object 'yprob' not found

> preds <- prediction(pruned.tree7$frame$yprob, names(pruned.tree7$frame$yprob))

Error in prediction(pruned.tree7$frame$yprob, names(pruned.tree7$frame$yprob)) : Format of labels is invalid.

> preds <- prediction(pruned.tree7$frame$yprob, dimnames(pruned.tree7$frame$yprob))

Error in prediction(pruned.tree7$frame$yprob, dimnames(pruned.tree7$frame$yprob)) : Number of predictions in each run must be equal to the number of labels for each run.

I have searched and found this link: ROCR Package Documentation It mentions the topic of cross-validation. However, it does not make sense to me.

Thank you in advance!!

0

There are 0 answers