Easy way of counting precision, recall and F1-score in R

后端 未结 7 1279
不思量自难忘°
不思量自难忘° 2021-01-31 04:45

I am using an rpart classifier in R. The question is - I would want to test the trained classifier on a test data. This is fine - I can use the predict.rpart<

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 05:29

    The ROCR library calculates all these and more (see also http://rocr.bioinf.mpi-sb.mpg.de):

    library (ROCR);
    ...
    
    y <- ... # logical array of positive / negative cases
    predictions <- ... # array of predictions
    
    pred <- prediction(predictions, y);
    
    # Recall-Precision curve             
    RP.perf <- performance(pred, "prec", "rec");
    
    plot (RP.perf);
    
    # ROC curve
    ROC.perf <- performance(pred, "tpr", "fpr");
    plot (ROC.perf);
    
    # ROC area under the curve
    auc.tmp <- performance(pred,"auc");
    auc <- as.numeric(auc.tmp@y.values)
    
    ...
    

提交回复
热议问题