MCPcopy Create free account
hub / github.com/catboost/catboost / select_threshold

Function select_threshold

catboost/python-package/catboost/utils.py:491–538  ·  view source on GitHub ↗

Selects a threshold for prediction. Parameters ---------- model : catboost.CatBoost The trained model. data : catboost.Pool or list of catboost.Pool Set of samples to build ROC curve with. If set, curve parameter must not be set. curve : tuple of t

(model=None, data=None, curve=None, FPR=None, FNR=None, thread_count=-1)

Source from the content-addressed store, hash-verified

489
490
491def select_threshold(model=None, data=None, curve=None, FPR=None, FNR=None, thread_count=-1):
492 """
493 Selects a threshold for prediction.
494
495 Parameters
496 ----------
497 model : catboost.CatBoost
498 The trained model.
499
500 data : catboost.Pool or list of catboost.Pool
501 Set of samples to build ROC curve with.
502 If set, curve parameter must not be set.
503
504 curve : tuple of three arrays (fpr, tpr, thresholds)
505 ROC curve points in format of get_roc_curve returned value.
506 If set, data parameter must not be set.
507
508 FPR : desired false-positive rate
509
510 FNR : desired false-negative rate (only one of FPR and FNR should be chosen)
511
512 thread_count : int (default=-1)
513 Number of threads to work with.
514 If -1, then the number of threads is set to the number of CPU cores.
515
516 Returns
517 -------
518 threshold : double
519 """
520 if data is not None:
521 if curve is not None:
522 raise CatBoostError('Only one of the parameters data and curve should be set.')
523 if model is None:
524 raise CatBoostError('model and data parameters should be set when curve parameter is None.')
525 if isinstance(data, Pool):
526 data = [data]
527 if not isinstance(data, list):
528 raise CatBoostError('data must be a catboost.Pool or list of pools.')
529 for pool in data:
530 if not isinstance(pool, Pool):
531 raise CatBoostError('one of data pools is not catboost.Pool')
532 return _select_threshold(model._object, data, None, FPR, FNR, thread_count)
533 elif curve is not None:
534 if not (isinstance(curve, list) or isinstance(curve, tuple)) or len(curve) != 3:
535 raise CatBoostError('curve must be list or tuple of three arrays (fpr, tpr, thresholds).')
536 return _select_threshold(None, None, curve, FPR, FNR, thread_count)
537 else:
538 raise CatBoostError('One of the parameters data and curve should be set.')
539
540
541def quantize(

Callers 3

do_test_rocFunction · 0.90

Calls 3

isinstanceFunction · 0.85
lenFunction · 0.85
CatBoostErrorClass · 0.50

Tested by 2

do_test_rocFunction · 0.72