skcriteria.extend module

Functionalities for the user’s extension of scikit-criteria.

This module introduces decorators that enable the creation of aggregation and transformation models using only functions.

It is important to note that models created with these decorators are much less flexible than those created using inheritance and lack certain properties of real objects.

exception skcriteria.extend.NonStandardNameWarning[source]

Bases: UserWarning

Custom warning class to indicate that a name does not follow a specific standard.

This warning is raised when a given name does not adhere to the specified naming convention.

skcriteria.extend.mkagg(maybe_func=None, **hparams)[source]

Decorator factory function for creating aggregation classes.

Parameters:
  • maybe_func (callable, optional) –

    Optional aggregation function to be wrapped into a class. If provided, the decorator is applied immediately.

    The decorated function should receive the parameters ‘matrix’, ‘objectives’, ‘weights’, ‘dtypes’, ‘alternatives’, ‘criteria’, ‘hparams’, or kwargs.

    Additionally, it should return an array with rankings for each alternative and an optional dictionary with calculations that you wish to store in the ‘extra’ attribute of the ranking.”

  • **hparams (keyword arguments) – Hyperparameters specific to the aggregation function.

Returns:

Agg – Aggregation class decorator or Aggregatio model with added functionality.

Return type:

class or decorator

Notes

This decorator is designed for creating aggregation model from aggregation functions. It provides an interface for creating aggregated decision-making models.

Examples

>>> @mkagg
>>> def MyAgg(**kwargs):
>>>     # Implementation of the aggregation function

The above example will create an aggregation class with the name ‘MyAgg’ based on the provided aggregation function.

>>> @mkagg(foo=1)
>>> def MyAgg(**kwargs):
>>>     # Implementation of the aggregation function

The above example will create an aggregation class with the specified hyperparameter ‘foo’ and the name ‘MyAgg’.

skcriteria.extend.mktransformer(maybe_func=None, **hparams)[source]

Decorator factory function for creating transformation classes.

Parameters:
  • maybe_func (callable, optional) –

    Optional transformation function to be wrapped into a class. If provided, the decorator is applied immediately.

    The decorated function should receive the parameters ‘matrix’, ‘objectives’, ‘weights’, ‘dtypes’, ‘alternatives’, ‘criteria’, ‘hparams’, or kwargs.

    In addition, it must return a dictionary whose keys are some as the received parameters (including the keys in ‘kwargs’). These values replace those of the original array. If you return ‘hparams,’ the transformer will ignore it.

    If you want the transformer to infer the types again, return dtypes with value None.

    It is the function’s responsibility to maintain compatibility.

  • **hparams (keyword arguments) – Hyperparameters specific to the transformation function.

Returns:

Trans – Transformation class decorator or Transformation model with added functionality.

Return type:

class or decorator

Notes

This decorator is designed for creating transformation models from transformation functions. It provides an interface for creating transformed decision-making models.

Examples

>>> @mktrans
>>> def MyTrans(**kwargs):
>>>     # Implementation of the transformation function
>>>     pass

The above example will create a transformation class with the name ‘MyTrans’ based on the provided transformation function.

>>> @mktrans(foo=1)
>>> def MyTrans(**kwargs):
>>>     # Implementation of the transformation function
>>>     pass

The above example will create a transformation class with the specified hyperparameter ‘foo’ and the name ‘MyTrans’.