美文网首页
利用rpy2在python上进行delong test

利用rpy2在python上进行delong test

作者: Williamongh | 来源:发表于2020-04-20 18:26 被阅读0次
import numpy as np
import rpy2.robjects as robj
r = robj.r
from rpy2.robjects.packages import importr

def roc_test_r(targets_1, scores_1, targets_2, scores_2, method='delong'):
    # method: “delong”, “bootstrap” or “venkatraman”
    importr('pROC')
    robj.globalenv['targets_1'] = targets_1 = robj.FloatVector(targets_1)
    robj.globalenv['scores_1'] = scores_1 = robj.FloatVector(scores_1)
    robj.globalenv['targets_2'] = targets_2 = robj.FloatVector(targets_2)
    robj.globalenv['scores_2'] = scores_2 = robj.FloatVector(scores_2)

    r('roc_1 <- roc(targets_1, scores_1)')
    r('roc_2 <- roc(targets_2, scores_2)')
    r('result = roc.test(roc_1, roc_2, method="%s")' % method)
    p_value = r('p_value = result$p.value')
    return np.array(p_value)[0]

相关文章

网友评论

      本文标题:利用rpy2在python上进行delong test

      本文链接:https://www.haomeiwen.com/subject/dwrjihtx.html