uqmodels package

Subpackages

Submodules

uqmodels.UQModel module

class uqmodels.UQModel.UQModel(UQEstimator_initializer=<class 'uqmodels.modelization.ML_estimator.random_forest_UQ.RF_UQEstimator'>, UQEstimator_params={'beta': 0.05, 'estimator': RandomForestRegressor(ccp_alpha=1e-05, max_depth=15, max_features=0.9, max_samples=0.7, min_impurity_decrease=1e-05, min_samples_leaf=5, min_samples_split=5, n_estimators=125), 'n_jobs': 4, 'pretuned': False, 'rescale': True, 'type_UQ': 'var_A&E', 'use_biais': True, 'var_min': 1e-05}, name='UQModel', predictor=None, preprocessor=None, list_predict_KPI_processors=None, list_score_KPI_processors=None, reduc_filter=None, roll=None, cache_manager=<uqmodels.processing.Cache_manager object>, save_result=False, save_models=False, random_state=None, **kwargs)[source]

Bases: BaseEstimator

UQModel class : instanciate a pipeline of model estimation, model UQ estimation and post processing as a (Fit,Predict,Score) triplet of method

fit(X, y=None, sample_weight=None, skip_UQEstimator=False, **kwargs)[source]

Fit method that apply fit method of (predictor), UQEstimators, predict_KPI_processors, score_KPI_processors :param X: Features :type X: np.array :param y: Targets/observations :type y: np.array :param sample_weight: sample_weight. Defaults to None. :type sample_weight: np.array or None, optional

fit_with_generator(data_generator, shuffle=True, **kwargs)[source]

Specific fit method that handle data_generator

Parameters:
  • data_generator (datagenerator) – Iterative object that provide : X, y, sample_weight, x_split, context, objective, source (see data_generator)

  • shuffle (bool, optional) – use shuffle or not. Defaults to True.

load(path=None, name='UQModel')[source]

UQ model load procedure : recovers UQ model structure, then predictor (if existe), then UQestimators

Parameters:
  • path (str, optional) – path of UQmodels save if none use path store in cache manager

  • name (str, optional) – name of UQmodels to load uf none use UQModel name

predict(X, name_save='output.p', **kwargs)[source]

Predict method that apply predictor and UQestimators predict method, then compute predict_KPIs by use transform methods of predict_KPI_Processors

Parameters:
  • X (np.array) – feature

  • name_save (str, optional) – file_name for (Predictor) and UQEstimator outputs save file. Defaults to β€œoutput.p”.

Returns:

prediction and list of KPIs or KPI if len(list==1)

Return type:

pred, list_KPI_output

predict_with_generator(data_generator, **kwargs)[source]

specific predict method that handle data_generator

Parameters:

data_generator (datagenerator) – Iterative object that provide : X, y, sample_weight, x_split, context, objective, source (see data_generator)

Returns:

list of (pred, UQ)

save(path=None, name=None)[source]

UQ model save procedure : recovers UQ model structure, then predictor (if existe), then UQestimators

Parameters:
  • path (path, optional) – path of UQmodels save

  • name (name, optional) – name of UQmodels to load

score(X, y=None, name_save='output', **kwargs)[source]

Score method that produce score KPI that transform y observation and (pred,UQ) UQestimator outputs into a KPI according to score_KPI_processors

Parameters:
  • X (np.array) – Features

  • y (np.array) – Targets/obserbations

Returns:

list_KPI_output or KPI_ouput if len(list)==1

Return type:

list_KPI_output

score_with_generator(data_generator, **kwargs)[source]

specitic score method that handle data_generator

Parameters:

data_generator (datagenerator) – Iterative object that provide : X, y, sample_weight, x_split, context, objective, source (see data_generator)

Returns:

list of score_KPI or score_KPI if len(list)==1

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$', skip_UQEstimator: bool | None | str = '$UNCHANGED$') UQModel

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:
  • sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in fit.

  • skip_UQEstimator (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for skip_UQEstimator parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_predict_request(*, name_save: bool | None | str = '$UNCHANGED$') UQModel

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:

name_save (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for name_save parameter in predict.

Returns:

self – The updated object.

Return type:

object

set_score_request(*, name_save: bool | None | str = '$UNCHANGED$') UQModel

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:

name_save (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for name_save parameter in score.

Returns:

self – The updated object.

Return type:

object

uqmodels.custom_UQModel module

class uqmodels.custom_UQModel.MultiDEEPUQModel(UQEstimator_initializer, UQEstimator_params, list_sources, cut_params=(0.001, 0.999), multiscale_anomscore_params=None, name='MultiDEEPUQModel', cache_manager=<uqmodels.processing.Cache_manager object>, save_result=True, save_models=True, with_generator=True, reduc_filter=None, random_state=None)[source]

Bases: UQModel

UQModel class for UQestimators that perform multisource forecast with UQ.

fit(X, y, sample_weight=None, skip_UQEstimator=False, shuffle=True, **kwargs)[source]

Fit method that apply fit method of (predictor), UQEstimators, predict_KPI_processors, score_KPI_processors :param X: Features :type X: np.array :param y: Targets/observations :type y: np.array :param sample_weight: sample_weight. Defaults to None. :type sample_weight: np.array or None, optional

multi_score_reshape(y=None, pred=None, UQ=None, mask=None)[source]

Reshape from (n_sample,n_sources*s_chan) to List of n_sources (n_sample,n_chan) elements

Parameters:
  • y (np.array, optional) – y to reshape or None. Defaults to None.

  • pred (np.array, optional) – pred to reshape or None. Defaults to None.

  • UQ (np.array, optional) – UQ to reshape or None. Defaults to None.

  • return – list_y,list_pred,list_UQ

predict(X, name_save='output.p')[source]

Predict method that apply predictor and UQestimators predict method, then compute predict_KPIs by use transform methods of predict_KPI_Processors

Parameters:
  • X (np.array) – feature

  • name_save (str, optional) – file_name for (Predictor) and UQEstimator outputs save file. Defaults to β€œoutput.p”.

Returns:

prediction and UQmeasure

Return type:

pred, UQ

score(X, y, **kwargs)[source]

Score method that produce score KPI that transform y observation and (pred,UQ) UQestimator outputs into a KPI according to score_KPI_processors

Parameters:
  • X (np.array) – Features

  • y (np.array) – Targets/obserbations

Returns:

(List_Pred,list_UQ),KPI_anom

Return type:

list_KPI_output

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$', shuffle: bool | None | str = '$UNCHANGED$', skip_UQEstimator: bool | None | str = '$UNCHANGED$') MultiDEEPUQModel

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:
  • sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in fit.

  • shuffle (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for shuffle parameter in fit.

  • skip_UQEstimator (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for skip_UQEstimator parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_predict_request(*, name_save: bool | None | str = '$UNCHANGED$') MultiDEEPUQModel

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:

name_save (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for name_save parameter in predict.

Returns:

self – The updated object.

Return type:

object

class uqmodels.custom_UQModel.MultiUQModel(UQEstimator_initializer, UQEstimator_params, tunning_params, list_sources, list_delta=None, target_delta=None, multiscale_anomscore_params=None, models_in_ram=True, cut_params=(0.001, 0.999), name='Multi_RFUQModels', cache_manager=<uqmodels.processing.Cache_manager object>, save_models=True, save_result=True, random_state=None)[source]

Bases: UQModel

Instanciation of UQModels that apply an UQestimator for each sources and combine results for compute multidimensional anomaly score

No predict_KPIs_processor Multiscale_Anomscore_processor as score_predict_KPIS_processor : to product multidimensional anomaly score matrix

fit(X, y, sample_weight=None, skip_UQEstimator=False, **kwargs)[source]

Fit method that apply fit method of (predictor) for eachs source_UQEstimators, then fit the Anom_KPI_processors.

Parameters:
  • X (np.array) – Features

  • y (np.array) – Targets/observations

  • sample_weight (np.array or None, optional) – sample_weight. Defaults to None.

fit_with_generator(data_generator, skip_UQEstimator=False, shuffle=True, **kwargs)[source]

Specific fit method that handle data_generator

Parameters:
  • data_generator (datagenerator) – Iterative object that provide : X, y, sample_weight, x_split, context, objective, source (see data_generator)

  • shuffle (bool, optional) – use shuffle or not. Defaults to True.

get_model(id_source)[source]

Get model of an id_source

Parameters:
  • model (UQEstimator) – UQEstimator to set

  • id_source (int) – Id_source

predict(X, recovers_at_end=False, **kwargs)[source]

Predict method that applies predictor and UQestimators predict method, then computes predict_KPIs by using transform methods of predict_KPI_Processors.

Parameters:
  • X (np.array) – feature

  • name_save (str, optional) – file_name for (Predictor) and UQEstimator outputs save file. Defaults to β€œoutput.p”.

Returns:

prediction and UQmeasure

Return type:

pred, UQ

predict_with_generator(data_generator, recovers_at_end=True, **kwargs)[source]

specific predict method that handle data_generator

Parameters:

data_generator (datagenerator) – Iterative object that provide : X, y, sample_weight, x_split, context, objective, source (see data_generator)

Returns:

list of (pred, UQ)

score(X, y, **kwargs)[source]

Score method that produces score KPI by transforming y observation and (pred,UQ) UQestimator outputs into a KPI according to score_KPI_processors.

Parameters:
  • X (np.array) – Features

  • y (np.array) – Targets/obserbations

Returns:

list_KPI_output or KPI_ouput if len(list)==1

Return type:

list_KPI_output

score_with_generator(data_generator, recovers_at_end=True, **kwargs)[source]

specitic score method that handle data_generator

Parameters:

data_generator (datagenerator) – Iterative object that provide : X, y, sample_weight, x_split, context, objective, source (see data_generator)

Returns:

list of score_KPI or score_KPI if len(list)==1

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$', skip_UQEstimator: bool | None | str = '$UNCHANGED$') MultiUQModel

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:
  • sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in fit.

  • skip_UQEstimator (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for skip_UQEstimator parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_model(model, id_source)[source]

Set model of an id_source

Parameters:
  • model (UQEstimator) – UQEstimator to set

  • id_source (int) – Id_source

set_predict_request(*, recovers_at_end: bool | None | str = '$UNCHANGED$') MultiUQModel

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:

recovers_at_end (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for recovers_at_end parameter in predict.

Returns:

self – The updated object.

Return type:

object

class uqmodels.custom_UQModel.TADKIT_UQModel(y_shape, n_window=20, model='RF_UQ', model_params=None, epochs=30, reduc_coef=True, beta=0.001, random_state=None, cache_manager=<uqmodels.processing.Cache_manager object>)[source]

Bases: UQModel

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$', skip_UQEstimator: bool | None | str = '$UNCHANGED$') TADKIT_UQModel

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:
  • sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in fit.

  • skip_UQEstimator (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for skip_UQEstimator parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_predict_request(*, name_save: bool | None | str = '$UNCHANGED$') TADKIT_UQModel

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:

name_save (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for name_save parameter in predict.

Returns:

self – The updated object.

Return type:

object

set_score_request(*, name_save: bool | None | str = '$UNCHANGED$') TADKIT_UQModel

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:

name_save (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for name_save parameter in score.

Returns:

self – The updated object.

Return type:

object

class uqmodels.custom_UQModel.UQModel_KPI(UQEstimator_initializer, UQEstimator_params, name='UQModel', predictor=None, preprocessor=None, list_alpha=[0.025, 0.16, 0.84, 0.975], list_percent_escore=[0.5, 0.8, 0.95, 0.98, 0.995, 1], reduc_filter_pred=None, reduc_filter_KPI=None, roll_KPI=1, anom_with_born=False, beta=0.01, var_min=0.001, cache_manager=<uqmodels.processing.Cache_manager object>, q_Eratio=3, mode_epistemic_indicator='levels', random_state=None)[source]

Bases: UQModel

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$', skip_UQEstimator: bool | None | str = '$UNCHANGED$') UQModel_KPI

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:
  • sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in fit.

  • skip_UQEstimator (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for skip_UQEstimator parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_predict_request(*, name_save: bool | None | str = '$UNCHANGED$') UQModel_KPI

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:

name_save (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for name_save parameter in predict.

Returns:

self – The updated object.

Return type:

object

set_score_request(*, name_save: bool | None | str = '$UNCHANGED$') UQModel_KPI

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:

name_save (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for name_save parameter in score.

Returns:

self – The updated object.

Return type:

object

uqmodels.processing module

class uqmodels.processing.Cache_manager(save_API=<function write>, load_API=<function read>, storing='', default_filename='', query_to_cache_query=None)[source]

Bases: object

default_query_to_cache_query(query, filename=None, values=None)[source]

default_query_to_keys : function that create a Save/Load query for the cache_manager load/save api_function from query

Parameters:
  • query (_type_) – query to interpret

  • filename (str, optional) – default_storage_filename. Defaults to β€˜object.p’.

  • values (obj or None, optional) – obj to store by load_API/ if None then query_to_save_API

Returns:

dict_parameters to provide to save_API or load_API

Return type:

dict_new_q

load(query, filename=None)[source]

load obj at query + filname location using save_API

Parameters:
  • query (dict) – query to interpret by query_to_cache_query

  • filename (str, optional) – filename of object if not provided by query. Defaults to None.

Raises:
  • FileNotFoundError – _description_

  • FileNotFoundError – _description_

Returns:

_description_

Return type:

_type_

save(query, obj, filename=None, verbose=False)[source]

save obj at query + filename location using load_API

Parameters:
  • query (dict) – query to interpret by query_to_cache_query

  • obj (obj) – object to store by save_API

  • filename (_type_, optional) – filename of object if not provided by query. Defaults to None.

class uqmodels.processing.Data_loader(data_loader_api=<function read>)[source]

Bases: ABC

load(dict_query)[source]

load form a dict_query that will be provide to the data_loader_api function

Parameters:

dict_query (dict) – query as a dict that contains argument of the self.data_loader_api

Raises:

FileNotFoundError – error if file not found

Returns:

selected_data loaded by the data_loader_api function from the dict_query

Return type:

selected_data

exception uqmodels.processing.EstimatorNotFitted[source]

Bases: Exception

class uqmodels.processing.MyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class uqmodels.processing.Pipeline(data_loader=None, list_processors=[], verbose=False, skip_cache=False)[source]

Bases: BaseEstimator

fit(query, save_processor=False)[source]
Apply a fiting procedure to the pipeline with data_loader and a list of processor to a query/querries_list

if no data_loader provide data instead of β€œquery”

Parameters:

query_or_list (_type_) – Query or List of query to provide to the data_loader

fit_transform(query_or_list, save_processor=False)[source]

Fit tranform procedure : apply sucessively fit then transform

Parameters:
  • query_or_list (_type_) – query or list of query to apply

  • save_processor (bool, optional) – _description_. Defaults to False.

Returns:

_description_

Return type:

_type_

set_fit_request(*, query: bool | None | str = '$UNCHANGED$', save_processor: bool | None | str = '$UNCHANGED$') Pipeline

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:
  • query (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for query parameter in fit.

  • save_processor (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for save_processor parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_transform_request(*, query_or_list: bool | None | str = '$UNCHANGED$') Pipeline

Request metadata passed to the transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a pipeline.Pipeline. Otherwise it has no effect.

Parameters:

query_or_list (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for query_or_list parameter in transform.

Returns:

self – The updated object.

Return type:

object

transform(query_or_list)[source]
Apply a pipeline with data_loader and a list of processor to a query o a list of query provide a generator

If query not found in cache, Load data and tranform data using fitted processor If no data_loader provide data instead of β€œquery_or_list”

Parameters:

query_or_list (query) – Query or List of query to provide to the data_loader

Returns:

a Data gerenator that provide returned by the last Processor of the piepline

Yields:

generator – generator that will apply pipeline to each querries provided.

class uqmodels.processing.Processor(name='processor', cache=None, update_query=None, **kwargs)[source]

Bases: object

default_update_query(query)[source]
fit(data=None)[source]

Fit Processor using data

Parameters:

data (obj, optional) – data. Defaults to None.

fit_transform(data=None)[source]

Fit Processor and apply it on data

Parameters:

data (obj, optional) – data. Defaults to None.

load(query=None, name=None)[source]

Load method to load Processor at query+name location using cache_manager

Parameters:
  • query (dict, optional) – query_paramaters. Defaults to None.

  • name (_type_, optional) – filename of obj to load. Defaults to None.

save(query=None, object=None, name=None)[source]

Save method to store object at queery+name location using cache_manager

Parameters:
  • query (dict, optional) – query_paramaters. Defaults to None.

  • object (obj, optional) – object to store. Defaults to None.

  • name (_type_, optional) – filename of obj to store. Defaults to None.

transform(data=None)[source]

Apply Processor to data

Parameters:

data (obj, optional) – data. Defaults to None.

update_query(query)[source]

Apply the update_query_function provided at init to update query :param query: query :type query: dict

Returns:

updated query

Return type:

new_query

use_cache(query)[source]

Use_cache manager to check if there is cache link to data already processed

Parameters:

query (dict) – query

Raises:

FileNotFoundError – cache Not Found error caught by method that called use_case

Returns:

data if

Return type:

data

uqmodels.processing.read(storing, keys, **kwargs)[source]

Read API for file management

Parameters:
  • storing (str) – global path of values to read

  • keys (list of str) – local path as list of folder + filename as last key

uqmodels.processing.read_function(filename)[source]

Auxiliar read function for file manipulation that hold csv/ pickle /json

Parameters:

filename (str) – name of file

Raises:

FileNotFoundError – _description_

Returns:

values loaded

Return type:

values

uqmodels.processing.set_query_to_cache_query(filename, with_arborescence=False, storing=None)[source]
Generate function that translate query to a cache API query

Only compatible with write/read uqmodels.processing API

Parameters:
  • filename (_type_) – Name of file to store data & processor

  • with_arborescence (bool, optional) – store in file arborescence. Defaults to False.

Returns:

function for cache manager object

Return type:

query_to_cache_query

uqmodels.processing.split_path(path)[source]

Split path into list of folder name using path.split iterativly.

Parameters:

path (str) – path

uqmodels.processing.to_list(obj)[source]

Put obj in list or do nothing if obj is already a list

uqmodels.processing.write(storing, keys, values, **kwargs)[source]

Write API for file management

Parameters:
  • storing (str) – global path of values to read

  • keys (list of str) – local path as list of folder + filename as last key

  • values (obj) – values to write

uqmodels.processing.write_function(values, filename)[source]

Auxiliar write function for file manipulation that hold csv/ pickle /json

Parameters:
  • values (obj) – values to store

  • filename (str) – name of file

Raises:

FileNotFoundError – Error raise when file is not found

uqmodels.utils module

uqmodels.utils.Extract_dict(dictionaire, str_keys)[source]
class uqmodels.utils.GenericCalibrator(type_res='res', mode='symetric', name=None, alpha=0.1)[source]

Bases: object

calibrate(y_pred, y_pred_lower, y_pred_upper, sigma_pred, **kwargs)[source]
estimate(y_true, y_pred, y_pred_lower, y_pred_upper, sigma_pred, **kwargs)[source]
uqmodels.utils.add_random_state(random_state, values)[source]

hold addition with possible None values

Parameters:
  • random_state (int or None) – Random state

  • values (int) – Values to add

Returns:

int or None

Return type:

random_state

uqmodels.utils.agg_func(list_: Iterable)[source]
uqmodels.utils.agg_list(list_: Iterable)[source]
uqmodels.utils.apply_conv(score, filt=None, reduc_filter=None)[source]

Apply naivly by dimension a convolution to s using filt as filter

Parameters:
  • s (np.array) – score to 1D convolute

  • filt (np.array) – filter to apply

Returns:

convoluted score

Return type:

s

uqmodels.utils.apply_mask(list_or_array_or_none, mask, axis=0, mode='bool_array')[source]
Select subpart of an array/list_of_array/tupple using a mask and np.take function.

If list_or_array_or_none is array, then direclty apply selection on it. else if it is a Tupple or list of array apply it on array in the list/tupple structure

Parameters:
  • list_or_array_or_none (_type_) – ND array (list or tupple or ND.array)

  • mask (_type_) – Mask as boolean array or indices array.

  • axis (int, optional) – axis on sub array to apply. Defaults to 1.

  • mode (str, optional) – if β€˜bool_array’, turn bool_array_mask into an indice_array. Defaults to β€˜bool_array’.

Returns:

Sub_selected list of array or Ndarray

Return type:

(List or Tuple or array or Ndarray)

uqmodels.utils.apply_middledim_reduction(ndarray, reduc_filter=None, roll=0)[source]

Apply middledim using ponderate mean reduc_filter weigth or do nothing

Parameters:
  • ndarray (np.array) – object to reduce

  • reduc_filter (np.array) – ponderate weigth for reduction

Returns:

reduced object

Return type:

reduced_ndarray

uqmodels.utils.autocorr(x)[source]

Compute autocorrelation of x

uqmodels.utils.aux_tuning(model, X, Y, params=None, score='neg_mean_squared_error', n_esti=100, folds=4, random_state=None)[source]

Random_search with sequential k-split

Parameters:
  • model (scikit model) – Estimator

  • X ([type]) – Features

  • Y ([type]) – Target

  • params ([type], optional) – parameter_grid. Defaults to None.

  • score (str, optional) – score. Defaults to β€˜neg_mean_squared_error’.

  • n_esti (int, optional) – Number of grid try . Defaults to 100.

  • folds (int, optional) – Number of sequential fold. Defaults to 4.

  • verbose (int, optional) – [description]. Defaults to 0.

  • random_state (bool) – handle experimental random using seeds.

uqmodels.utils.base_cos_freq(array, freq=[2])[source]

Transform 1D modulo features [1, N] in cyclic (cos,sin) features for given freq

uqmodels.utils.coefficients_spreaded(X)[source]
uqmodels.utils.compute_born(y_pred, sigma, alpha, mode='sigma')[source]

Compute y_upper and y_lower boundary from gaussian hypothesis (sigma or 2sigma)

Parameters:
  • y_pred (array) – Mean prediction

  • sigma (array) – Variance estimation

  • alpha (float) – Misscoverage ratio

  • mode (str) – Distribution hypothesis

  • (sigma – gaussian residual hypothesis, 2sigma : gaussian positive and negative residual hypothesis)

Returns:

Lower and upper bondary of Predictive interval

Return type:

(y_lower,y_upper)

uqmodels.utils.convolute_1D(array, filter=None)[source]

Convolution by dimension for 1 od 2D array using np.convolve

Parameters:
  • array (_type_) – array_to_convolve

  • filter (_type_, optional) – convolution fitler. Defaults to None.

Raises:

ValueError – dimension error

Returns:

array_convoluted

Return type:

array

uqmodels.utils.corr_matrix_array(m, a)[source]
Parameters:
  • a (numpy array)

  • v (true val)

Returns:

c – correlation coefficients of v against matrix m

Return type:

numpy array

uqmodels.utils.cum_sum_consecutive_zero(array)[source]
Count consecutive 0

1 0 1 0 0 0 -> 0 1 0 1 2 3

Parameters:

array (_type_) – array of consecutive 0

Returns:

_description_

Return type:

_type_

uqmodels.utils.cut(values, cut_min, cut_max)[source]

Apply percentile minimal and maximal threeshold

Parameters:
  • values (_type_) – values to cut

  • cut_min (_type_) – percentile of the minimam cut threeshold

  • cut_max (_type_) – percentile of the maximal cut threeshold

Returns:

_description_

Return type:

_type_

uqmodels.utils.dimensional_reduction(data, mode='umap', reducer=None, fit=True, **kwargs)[source]
uqmodels.utils.expand_flag(flag)[source]
uqmodels.utils.fit_compute_lag(Y, lag=[1, 2, 3], delay=0)[source]

Create lag features from a numerical array :param Y: Target to extract lag-feature :type Y: float array :param lag: Lag number. Defaults to 3. :type lag: int, optional :param delay: Delay before 1 lag feature. Defaults to 0. :type delay: int, optional

uqmodels.utils.flatten(y)[source]
uqmodels.utils.format_data(self, X, y, fit=False, mode=None, flag_inverse=False)[source]

Feature and target Formatting

uqmodels.utils.generate_random_state(random_state=None)[source]

Drawn random number is random_state is None, else return random_state

Parameters:

random_state (int or None, optional) – random_state. Defaults to None.

Returns:

random_state int

Return type:

random_state

uqmodels.utils.get_coeff(alpha)[source]
uqmodels.utils.get_fold_nstep(size_window, size_subseq, padding)[source]
uqmodels.utils.mixture_quantile(pred, var_A, quantiles, n_jobs=5)[source]
uqmodels.utils.norm_signal(y)[source]
uqmodels.utils.propagate(bool_array, n_prop=1, inv=False, sym=False)[source]
uqmodels.utils.sizeof_fmt(num, suffix='B')[source]

by Fred Cirera, https://stackoverflow.com/a/1094933/1870254, modified

uqmodels.utils.stack_and_roll(array, horizon, lag=0, seq_idx=None, step=1)[source]

_summary_

Parameters:
  • array (_type_) – array 2D to stack and roll

  • horizon (_type_) – depth

  • lag (int, optional) – _description_. Defaults to 0.

  • seq_idx (_type_, optional) – _description_. Defaults to None.

  • step (int, optional) – _description_. Defaults to 1.

Returns:

_description_

Return type:

_type_

uqmodels.utils.stack_and_roll_layer(inputs, size_window, size_subseq, padding, name='')[source]
uqmodels.utils.threshold(array, min_val=None, max_val=None)[source]
Threshold an array with min_val as lower bound and max_val as upper bound

Can hold mutlidimensional threshold on last dimension

Parameters:
  • array (_type_) – array nd to threeshold

  • min_val (val, array or) – _description_

  • max_val (_type_) – _description_

uqmodels.utils.track_memory(string)[source]

Module contents