flexcv.model_mapping
This module contains the ModelConfigDict and ModelMappingDict classes. They can be used to construct a mapping which can be passed to flexcv.interface.CrossValidation Usage:
model_mapping = ModelMappingDict({
"ModelName1": ModelConfigDict(
{
"requires_inner_cv": False,
"n_trials": 100,
"n_jobs_model": 1,
"n_jobs_cv": 1,
"model": model_1,
"params": {},
"post_processor": model_1_post_func,
"mixed_model": mixed_model_1,
"mixed_post_processor": mixed_model_1_post_func,
"mixed_name": "MixedModel1"
}
),
"ModelName2": ModelConfigDict(
{
"requires_inner_cv": True,
"n_trials": 100,
"n_jobs_model": 1,
"n_jobs_cv": 1,
"model": model_2,
"params": {},
"post_processor": model_2_post_func,
"mixed_model": mixed_model_2,
"mixed_post_processor": mixed_model_2_post_func,
"mixed_name": "MixedModel2"
},
),
}
)
flexcv.model_mapping.ModelConfigDict
Bases: Dict[str, Type]
A dictionary that maps model configuration names to their corresponding types.
Default Values
To make working with this custom Dict-like class easy, we re-implemented the init method to set some default key-value pairs for us. If you don't pass them, it will set
- requires_inner_cv = False
- n_jobs_model = 1
- n_jobs_cv = 1
- params = {}
Usage
{ # TODO update this to correct defaults
"requires_inner_cv": bool,
# this flag can be set to control if a model is used in the inner cross validation.
# if set to False, the model will be instantiated in the outer cross validation without hyper parameter optimization.
"n_trials": int,
# number of trials to be used in hyper parameter optimization.
"n_jobs_model": 1,
# number of jobs to be used in the model. We use the sklearn convention here. We use the sklearn convention here.
# If your model does not support n_jobs, you can pass False here.
"n_jobs_cv": 1,
# number of jobs to be used in the inner cross validation/hyper parameter tuning. We use the sklearn convention here.
"model": BaseEstimator,
# pass your sklearn model here. It must be a class, not an instance.
"params": {},
# pass the parameters to be used in the model here. It must be a dictionary of optuna distributions or an empty dict.
"post_processor": flexcv.model_postprocessing.ModelPostProcessor,
# pass the post processor class to be used here. It must inherit from the flexcv.model_postprocessing.ModelPostProcessor abstract base class.
}
Source code in flexcv/model_mapping.py
flexcv.model_mapping.ModelMappingDict
Bases: Dict[str, ModelConfigDict]
A dictionary that maps model names to model configuration dicts. Usage:
model_mapping = ModelMappingDict({
"LinearModel": ModelConfigDict(
{...}
),
"SecondModel": ModelConfigDict(
{...}
),
)