compml.sklearn_utils#
Utilities that integrate scikit-learn with compml.
- compml.sklearn_utils.run_cross_val(estimators, algorithm_names, datasets, dataset_names, scoring, cv, *, n_jobs=None, fit_params=None, verbose=0, pre_dispatch='2*n_jobs', error_score=nan, **kwargs)[source]#
Run cross-validation per (dataset, algorithm) and build CVScores.
For each dataset and algorithm,
sklearn.model_selection.cross_val_scoreis called with a clone of the estimator. The resulting score vector fillsscores[d, a, :]wheredis the dataset index andathe algorithm index. The sample axis (third dimension) is ordered by runs, so all folds of run 0 appear first, then all folds of run 1, and so on.- Parameters:
estimators (
Sequence[Any]) – Sklearn-compatible estimators. Length must matchalgorithm_names.algorithm_names (
tuple[str,...]) – Name for each algorithm.datasets (
Sequence[tuple[Any,Any]]) – One pair per dataset. Length must matchdataset_names.dataset_names (
tuple[str,...]) – Name for each dataset.scoring (
str) – Sklearnscoringname. Stored asmetricon the result.cv (
Any) – Cross-validation strategy: can be integer fold count,LeaveOneOut,RepeatedKFold,RepeatedStratifiedKFold, or a splitter withn_splits(e.g.KFold,StratifiedKFold).n_jobs (
int|None) – Parallel jobs forcross_val_score.fit_params (
dict[str,Any] |None) – Parameters to pass to thefitmethod of the estimator.verbose (
int) – Verbosity forcross_val_score.pre_dispatch (
str|int) – Job batching forcross_val_score.error_score (
float|str) – Value assigned to failed fits incross_val_score.**kwargs (
Any) – Additional keyword arguments forwarded tocross_val_score.
- Returns:
Cross-validated scores with shape
(n_datasets, n_algorithms, n_samples).- Return type:
- Raises:
ImportError – If scikit-learn is not installed.
ValueError – On invalid inputs or when inferred
(n_runs, n_folds)does not matchcross_val_scoreoutput length.
- compml.sklearn_utils.run_hold_out(estimators, algorithm_names, datasets, dataset_names, scoring, *, test_size=0.25, train_size=None, random_state=None, shuffle=True, stratify=False, **kwargs)[source]#
Run hold-out per (dataset, algorithm) and build EvaluationScores.
For each dataset and algorithm,
sklearn.model_selection.train_test_splitis called with a clone of the estimator. The resulting score vector fillsscores[d, a, :]wheredis the dataset index andathe algorithm index.- Parameters:
estimators (
Sequence[Any]) – Sklearn-compatible estimators. Length must matchalgorithm_names.algorithm_names (
tuple[str,...]) – Name for each algorithm.datasets (
Sequence[tuple[Any,Any]]) – One pair per dataset. Length must matchdataset_names.dataset_names (
tuple[str,...]) – Name for each dataset.scoring (
str) – Sklearnscoringname. Stored asmetricon the result.test_size (
float|int) – Size of the test set (used intrain_test_split).train_size (
float|int|None) – Size of the train set (used intrain_test_split).random_state (
int|RandomState|None) – Random seed (used intrain_test_split).shuffle (
bool) – Whether to shuffle the data (used intrain_test_split).stratify (
bool) – Whether to stratify the data (used intrain_test_split).**kwargs (
Any) – Additional keyword arguments forwarded totrain_test_split.
- Returns:
Evaluation scores with shape
(n_datasets, n_algorithms, 1).- Return type:
- Raises:
ImportError – If scikit-learn is not installed.
ValueError – On invalid inputs.