roc_curve

In [ ]:
roc_curve(y_true: str, 
          y_score: str,
          input_relation: (str, vDataFrame),
          pos_label: (int, float, str) = 1,
          nbins: int = 30,
          auc_roc: bool = False,
          best_threshold: bool = False,
          cutoff_curve: bool = False,
          ax=None,
          **style_kwds,)

Draws the ROC Curve.

Parameters

Name Type Optional Description
y_true
str
Response column.
y_score
str
Prediction Probability.
input_relation
str / vDataFrame
Relation to use to do the scoring. The relation can be a view or a table or even a customized relation. For example, you could write: "(SELECT ... FROM ...) x" as long as an alias is given at the end of the relation.
pos_label
int / float / str
To compute the ROC Curve, one of the response column class has to be the positive one. The parameter 'pos_label' represents this class.
nbins
int
Curve number of bins.
auc_roc
bool
If set to True, the function will return the ROC AUC without drawing the curve.
best_threshold
bool
If set to True, the function will return the best threshold without drawing the curve. The best threshold is the threshold of the point which is the farest from the random line.
cutoff_curve
bool
If set to True, the Cutoff curve will be drawn.
ax
Matplotlib axes object
The axes to plot on.
**style_kwds
any
Any optional parameter to pass to the Matplotlib functions.

Returns

tablesample : An object containing the result. For more information, see utilities.tablesample.

Example

In [9]:
from verticapy import vDataFrame
vDataFrame("example_classification")
Out[9]:
123
y_score
Float
123
y_true
Int
123
y_pred
Int
10.26199263649447100
20.27176694921201100
30.28171556512481600
40.28770460382082500
50.29350374558954700
60.29475473826400300
70.29956294998781710
80.30291632758509100
90.30407271840812700
100.30557534591911110
110.31083566904061900
120.31083566904061910
130.31467749853206810
140.31477253779470100
150.31750485088406700
160.32104751313806500
170.32489831897123600
180.32731363487109100
190.32829095386794900
200.32953009702602600
210.33066748150804800
220.33169482269100700
230.33489128962507700
240.33922497543052100
250.34064941171806900
260.34091423176713810
270.3417832186944800
280.34245682384610900
290.34260753857422700
300.34338024998316910
310.34338024998316910
320.34561150957992100
330.34570335374319900
340.34634145992485510
350.34656637772198600
360.3472057446561800
370.34732028699124600
380.34736187971757800
390.34789564692799800
400.35004136859187200
410.35071366860872600
420.35109732823426910
430.35201683051264400
440.35205422026265600
450.35214685519674900
460.35223950125486600
470.35317513776240400
480.353939591619710
490.35399633359628110
500.35438162426483500
510.35438162426483500
520.35534256573520300
530.35713218534487400
540.35745549633516600
550.35767970835400900
560.35873803392421500
570.35921007559093200
580.35956601676426500
590.35964157471663400
600.3606028610532500
610.3606028610532500
620.3610107520836400
630.36225548197537500
640.36317857203857300
650.36360041860322700
660.36469384477953900
670.36490799275620200
680.36528884868614600
690.36710003571199800
700.36726258876552400
710.36742721303533500
720.36804829476348800
730.36922573004505800
740.36979771665863300
750.37055385826795500
760.37055385826795510
770.37075382592579300
780.3714004011799410
790.3720796383258600
800.3727222853597310
810.3727907403899600
820.3733725448129800
830.37380960466500900
840.37397337319599210
850.37397343724878400
860.37459538158701910
870.37658833829903100
880.37665348322195800
890.37728892220561600
900.37821722973346300
910.37882574407064300
920.37882574407064300
930.37882574407064310
940.37882574407064310
950.3791113212458100
960.38018743774818900
970.3803398381150100
980.38056806607898300
990.38073299525004600
1000.38087661750590600
Rows: 1-100 | Columns: 3
In [11]:
from verticapy.learn.model_selection import roc_curve
roc_curve("y_true", "y_score", "example_classification")
Out[11]:
threshold
false_positive
true_positive
10.01.01.0
20.03333333333333331.01.0
30.06666666666666671.01.0
40.11.01.0
50.1333333333333331.01.0
60.1666666666666671.01.0
70.21.01.0
80.2333333333333331.01.0
90.2666666666666670.9983471074380171.0
100.30.9900826446280990.997442455242967
110.3333333333333330.9702479338842980.989769820971867
120.3666666666666670.9057851239669420.971867007672634
130.40.7603305785123970.907928388746803
140.4333333333333330.4842975206611570.723785166240409
150.4666666666666670.2644628099173550.578005115089514
160.50.20.50383631713555
170.5333333333333330.1586776859504130.432225063938619
180.5666666666666670.1157024793388430.347826086956522
190.60.09090909090909090.273657289002558
200.6333333333333330.06942148760330580.232736572890026
210.6666666666666670.0561983471074380.191815856777494
220.70.03471074380165290.166240409207161
230.7333333333333330.03305785123966940.148337595907928
240.7666666666666670.0314049586776860.132992327365729
250.80.0280991735537190.107416879795396
260.8333333333333330.0280991735537190.0869565217391304
270.8666666666666670.01983471074380170.0767263427109974
280.90.01818181818181820.0664961636828645
290.9333333333333330.01157024793388430.0562659846547315
300.9666666666666670.003305785123966940.0255754475703325
311.00.00.0
Rows: 1-31 | Columns: 3
In [12]:
roc_curve("y_true", 
          "y_score", 
          "example_classification", 
          cutoff_curve = True)
Out[12]:
threshold
false_positive
true_positive
10.01.01.0
20.03333333333333331.01.0
30.06666666666666671.01.0
40.11.01.0
50.1333333333333331.01.0
60.1666666666666671.01.0
70.21.01.0
80.2333333333333331.01.0
90.2666666666666670.9983471074380171.0
100.30.9900826446280990.997442455242967
110.3333333333333330.9702479338842980.989769820971867
120.3666666666666670.9057851239669420.971867007672634
130.40.7603305785123970.907928388746803
140.4333333333333330.4842975206611570.723785166240409
150.4666666666666670.2644628099173550.578005115089514
160.50.20.50383631713555
170.5333333333333330.1586776859504130.432225063938619
180.5666666666666670.1157024793388430.347826086956522
190.60.09090909090909090.273657289002558
200.6333333333333330.06942148760330580.232736572890026
210.6666666666666670.0561983471074380.191815856777494
220.70.03471074380165290.166240409207161
230.7333333333333330.03305785123966940.148337595907928
240.7666666666666670.0314049586776860.132992327365729
250.80.0280991735537190.107416879795396
260.8333333333333330.0280991735537190.0869565217391304
270.8666666666666670.01983471074380170.0767263427109974
280.90.01818181818181820.0664961636828645
290.9333333333333330.01157024793388430.0562659846547315
300.9666666666666670.003305785123966940.0255754475703325
311.00.00.0
Rows: 1-31 | Columns: 3
In [8]:
# Best Cutoff
roc_curve("y_true",
          "y_score", 
          "example_classification", 
          best_threshold = True)
Out[8]:
0.466666666666667