#NEWLINE# def roc_curve( y_true , y_score , pos_label = None , sample_weight = None , drop_intermediate = True ) : #NEWLINE# #INDENT# 'Compute Receiver operating characteristic (ROC)\n\n    Note: this implementation is restricted to the binary classification task.\n\n    Read more in the :ref:`User Guide <roc_metrics>`.\n\n    Parameters\n    ----------\n\n    y_true : array, shape = [n_samples]\n        True binary labels in range {0, 1} or {-1, 1}.  If labels are not\n        binary, pos_label should be explicitly given.\n\n    y_score : array, shape = [n_samples]\n        Target scores, can either be probability estimates of the positive\n        class, confidence values, or non-thresholded measure of decisions\n        (as returned by "decision_function" on some classifiers).\n\n    pos_label : int\n        Label considered as positive and others are considered negative.\n\n    sample_weight : array-like of shape = [n_samples], optional\n        Sample weights.\n\n    drop_intermediate : boolean, optional (default=True)\n        Whether to drop some suboptimal thresholds which would not appear\n        on a plotted ROC curve. This is useful in order to create lighter\n        ROC curves.\n\n        .. versionadded:: 0.17\n           parameter *drop_intermediate*.\n\n    Returns\n    -------\n    fpr : array, shape = [>2]\n        Increasing false positive rates such that element i is the false\n        positive rate of predictions with score >= thresholds[i].\n\n    tpr : array, shape = [>2]\n        Increasing true positive rates such that element i is the true\n        positive rate of predictions with score >= thresholds[i].\n\n    thresholds : array, shape = [n_thresholds]\n        Decreasing thresholds on the decision function used to compute\n        fpr and tpr. `thresholds[0]` represents no instances being predicted\n        and is arbitrarily set to `max(y_score) + 1`.\n\n    See also\n    --------\n    roc_auc_score : Compute Area Under the Curve (AUC) from prediction scores\n\n    Notes\n    -----\n    Since the thresholds are sorted from low to high values, they\n    are reversed upon returning them to ensure they correspond to both ``fpr``\n    and ``tpr``, which are sorted in reversed order during their calculation.\n\n    References\n    ----------\n    .. [1] `Wikipedia entry for the Receiver operating characteristic\n            <https://en.wikipedia.org/wiki/Receiver_operating_characteristic>`_\n\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> from sklearn import metrics\n    >>> y = np.array([1, 1, 2, 2])\n    >>> scores = np.array([0.1, 0.4, 0.35, 0.8])\n    >>> fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2)\n    >>> fpr\n    array([ 0. ,  0.5,  0.5,  1. ])\n    >>> tpr\n    array([ 0.5,  0.5,  1. ,  1. ])\n    >>> thresholds\n    array([ 0.8 ,  0.4 ,  0.35,  0.1 ])\n\n    ' #NEWLINE# ( fps , tps , thresholds ) = _binary_clf_curve ( y_true , y_score , pos_label = pos_label , sample_weight = sample_weight ) #NEWLINE# if ( drop_intermediate and ( len ( fps ) > 2 ) ) : #NEWLINE# #INDENT# optimal_idxs = np . where ( np . r_ [ ( True , np . logical_or ( np . diff ( fps , 2 ) , np . diff ( tps , 2 ) ) , True ) ] ) [ 0 ] #NEWLINE# fps = fps [ optimal_idxs ] #NEWLINE# tps = tps [ optimal_idxs ] #NEWLINE# thresholds = thresholds [ optimal_idxs ] #NEWLINE# #UNINDENT# if ( ( tps . size == 0 ) or ( fps [ 0 ] != 0 ) ) : #NEWLINE# #INDENT# tps = np . r_ [ ( 0 , tps ) ] #NEWLINE# fps = np . r_ [ ( 0 , fps ) ] #NEWLINE# thresholds = np . r_ [ ( ( thresholds [ 0 ] + 1 ) , thresholds ) ] #NEWLINE# #UNINDENT# if ( fps [ ( - 1 ) ] <= 0 ) : #NEWLINE# #INDENT# warnings . warn ( 'No negative samples in y_true, false positive value should be meaningless' , UndefinedMetricWarning ) #NEWLINE# fpr = np . repeat ( np . nan , fps . shape ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# fpr = ( fps / fps [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# if ( tps [ ( - 1 ) ] <= 0 ) : #NEWLINE# #INDENT# warnings . warn ( 'No positive samples in y_true, true positive value should be meaningless' , UndefinedMetricWarning ) #NEWLINE# tpr = np . repeat ( np . nan , tps . shape ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tpr = ( tps / tps [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# return ( fpr , tpr , thresholds )