Toolsklearn: Toolsklearn

ToolsklearnR Documentation

Toolsklearn

Description

R6 class of the scikit-learn tool

Format

An R6 class object.

Details

Toolsklearn is a wrapper class for the precision-recall curve calculation of scikit-learn, which is a machine learning library for Python.

The calculation is performed by a standalone Python module that is bundled with prcbench and derived from the scikit-learn source code. As a result, scikit-learn itself is not required, but reticulate, a working Python installation, and numpy are. The tool can be created without them, whereas the actual calculation cannot be performed. In that case the tool returns a flat dummy curve instead of raising an error, in the same way as ToolAUCCalculator does without rJava, so that the predefined tool sets keep working on a machine without Python.

Initialising Python imports numpy, and the BLAS library behind numpy starts a thread pool sized to the number of cores. Those threads cost CPU time that the import itself never spends, so the pool is capped to two threads while the import runs. Set OMP_NUM_THREADS, OPENBLAS_NUM_THREADS, MKL_NUM_THREADS, or NUMEXPR_NUM_THREADS before the first tool is created to choose the size of the pool instead.

Two AUC calculation methods are available. aucType = 1 uses average precision, which is the summary scikit-learn recommends for precision-recall curves, whereas aucType = 2 uses the trapezoidal rule. The scikit-learn documentation discourages the use of the trapezoidal rule for precision-recall curves.

Timings of this tool are not comparable with those of the tools written in R. Every call crosses the R/Python boundary and converts the input and output vectors, and run_benchmark counts that overhead as part of the measurement. On a small test set it often dominates the curve calculation itself. The accuracy evaluation of run_evalcurve is unaffected.

Super class

ToolIFBase -> Toolsklearn

Methods

Public methods

Inherited methods

Toolsklearn$new()

Default class initialization method.

Usage
Toolsklearn$new(...)
Arguments
...

set value for drop_intermediate, aucType.


Toolsklearn$set_drop_intermediate()

A Boolean value to specify whether suboptimal thresholds are dropped.

Usage
Toolsklearn$set_drop_intermediate(val)
Arguments
val

TRUE: drop, FALSE: keep.


Toolsklearn$set_aucType()

Set the AUC calculation method

Usage
Toolsklearn$set_aucType(val)
Arguments
val

1: average precision, 2: trapezoidal rule


Toolsklearn$clone()

The objects of this class are cloneable with this method.

Usage
Toolsklearn$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

This class is derived from ToolIFBase. create_toolset for creating a list of tools.

Examples

## Initialization
toolsklearn <- Toolsklearn$new()

## Show object info
toolsklearn

## create_toolset should be used for benchmarking and curve evaluation
toolsklearn2 <- create_toolset("sklearn")


prcbench documentation built on Sept. 26, 2026, 5:06 p.m.