scales

This module gathers all data scales and their features.

class DiscreteQuantitativeScale(values, preference_direction=None, **kwargs)

Bases: QuantitativeScale

Class for discrete quantitative scale.

Parameters
  • values (List[float]) – numeric values that constitute the scale

  • preference_direction (Union[PreferenceDirection, None]) –

static binary()

Return binary scale.

Returns

Return type

DiscreteQuantitativeScale

classmethod fit(data, preference_direction=None, **kwargs)

Create a scale that fits the data.

Parameters
Returns

scale

Raises

TypeError – if data is not numeric

Return type

Self

property interval: Interval

Return interval on which scale is defined.

is_better(x, y)

Check if x is better than y according to this scale.

Parameters
  • x (Any) –

  • y (Any) –

Returns

Return type

bool

is_better_or_equal(x, y)

Check if x is better or equal to y according to this scale

Parameters
  • x (Any) –

  • y (Any) –

  • scale

Returns

Return type

bool

label(x)

Return scale value corresponding to given number.

Parameters

x (float) –

Returns

Raises

ValueError – if x is outside scale

Return type

Any

static normal()

Return normal scale.

Returns

Return type

QuantitativeScale

property numeric: QuantitativeScale

Return corresponding numeric scale.

range(nb=None)

Return range of value from scale.

Parameters

nb (Optional[int]) – number of values to return

Returns

Return type

List

value(x)

Return corresponding numeric value.

Parameters

x (Any) –

Returns

Raises

ValueError – if x is outside scale

Return type

float

class FuzzyScale(fuzzy, preference_direction=None, defuzzify_method='centre_of_gravity', **kwargs)

Bases: QualitativeScale

This class implements a MCDA fuzzy qualitative scale.

Parameters
  • fuzzy (Series) –

  • preference_direction (Union[PreferenceDirection, None]) –

  • defuzzify_method (str) –

Raises

TypeError

  • if fuzzy contains non-fuzzy numbers

defuzzify(method=None)

Defuzzify all fuzzy numbers using given method.

Parameters

method (Optional[str]) – method used to defuzzify (from mcda.core.functions.FuzzyNumber numeric methods)

Return type

Series

classmethod fit(data, preference_direction=None, **kwargs)

Create a scale that fits the data.

Parameters
Returns

scale

Return type

Self

fuzziness(fuzzy)

Returns the fuzziness of given fuzzy number w.r.t this scale.

Parameters

fuzzy (FuzzyNumber) –

Returns

Return type

float

property interval: Interval

Return interval on which scale is defined.

is_better(x, y)

Check if x is better than y according to this scale.

Parameters
  • x (Any) –

  • y (Any) –

Returns

Return type

bool

is_better_or_equal(x, y)

Check if x is better or equal to y according to this scale

Parameters
  • x (Any) –

  • y (Any) –

  • scale

Returns

Return type

bool

property is_fuzzy_partition: bool

Test whether the scale define a fuzzy partition.

Returns

label(x)

Return label associated to given number.

Parameters

x (float) –

Raises

ValueError – if x corresponds to no label

Returns

most probable label associated to given value

Return type

Any

property numeric: QuantitativeScale

Return corresponding numeric scale.

ordinal_distance(a, b)

Returns the ordinal distance between the labels (sorted by defuzzified values).

Parameters
  • a (Any) –

  • b (Any) –

Returns

Raises

ValueError – if a or b is not inside the scale

Return type

float

range(nb=None)

Return range of value from scale.

Parameters

nb (Optional[int]) – number of values to return (always ignored here)

Returns

Return type

List

similarity(fuzzy1, fuzzy2)

Returns similarity between both fuzzy numbers w.r.t this scale.

Parameters
Returns

Return type

float

Note

implementation based on [IMVM10]

specificity(fuzzy)

Returns the specificity of given fuzzy number w.r.t this scale.

Parameters

fuzzy (FuzzyNumber) –

Returns

Return type

float

Todo

check whether normalization should be done before computing area

value(x)

Return corresponding numeric value.

Parameters

x (Any) –

Returns

Return type

float

MAX = PreferenceDirection.MAX

User-friendly way to call PreferenceDirection.MAX

MIN = PreferenceDirection.MIN

User-friendly way to call PreferenceDirection.MIN

class NominalScale(labels, **kwargs)

Bases: Scale

This class implements a MCDA nominal scale.

Parameters

labels (List) –

classmethod fit(data, **kwargs)

Create a scale that fits the data.

Parameters

data (Series) –

Returns

scale

Return type

NominalScale

is_better(x, y)

Check if x is better than y according to this scale.

Parameters
  • x (Any) –

  • y (Any) –

Returns

Raises

TypeError – if scale is not ordinal

Return type

bool

is_better_or_equal(x, y)

Check if x is better or equal to y according to this scale

Parameters
  • x (Any) –

  • y (Any) –

  • scale

Returns

Return type

bool

range(nb=None)

Return range of value from scale.

Parameters

nb (Optional[int]) – number of values to return (always ignored here)

Returns

Return type

List

class PreferenceDirection(value)

Bases: Enum

Enumeration of MCDA preference directions.

MAX = 'MAX'
MIN = 'MIN'
classmethod content_message()

Return list of items and their values.

Returns

Return type

str

classmethod has_value(x)

Check if value is in enumeration.

Parameters

x (PreferenceDirection) –

Returns

Return type

bool

class QualitativeScale(values, preference_direction=None, **kwargs)

Bases: OrdinalScale, NominalScale

This class implements a MCDA qualitative scale.

Parameters
  • values (Series) – numeric series with labels as index

  • preference_direction (Union[PreferenceDirection, None]) –

Raises

TypeError

  • if values contains non-numeric values

Warning

This scale contains labels not values. values are only here to define a corresponding quantitative scale for default scale transformation. After calling transform_to() with no associated scale, the data is no longer considered inside the qualitative scale.

classmethod fit(data, preference_direction=None, **kwargs)

Create a scale that fits the data.

Parameters
Returns

scale

Return type

Self

property interval: Interval

Return interval on which scale is defined.

is_better(x, y)

Check if x is better than y according to this scale.

Parameters
  • x (Any) –

  • y (Any) –

Returns

Return type

bool

is_better_or_equal(x, y)

Check if x is better or equal to y according to this scale

Parameters
  • x (Any) –

  • y (Any) –

  • scale

Returns

Return type

bool

label(x)

Return label corresponding to given number.

Parameters

x (float) –

Raises

ValueError – if x corresponds to no label

Returns

Return type

Any

property numeric: QuantitativeScale

Return corresponding numeric scale.

range(nb=None)

Return range of value from scale.

Parameters

nb (Optional[int]) – number of values to return (always ignored here)

Returns

Return type

List

value(x)

Return corresponding numeric value.

Parameters

x (Any) –

Returns

Return type

float

class QuantitativeScale(arg1=-inf, dmax=inf, min_in=True, max_in=True, preference_direction=None, **kwargs)

Bases: OrdinalScale

Class for quantitative scale (interval based).

Parameters
  • arg1 (Union[float, Interval]) – min boundary of scale or complete interval

  • dmax (float) – max boundary of scale (only considered if arg1 type is not interval)

  • min_in (bool) – is min boundary inside scale or not

  • max_in (bool) – is max boundary inside scale or not

  • preference_direction (Union[PreferenceDirection, None]) –

Raises

ValueError – if dmin bigger than dmax

classmethod fit(data, preference_direction=None, **kwargs)

Create a scale that fits the data.

Parameters
Returns

scale

Raises

TypeError – if data is not numeric

Return type

Self

property interval: Interval

Return interval on which scale is defined.

is_better(x, y)

Check if x is better than y according to this scale.

Parameters
  • x (Any) –

  • y (Any) –

Returns

Return type

bool

is_better_or_equal(x, y)

Check if x is better or equal to y according to this scale

Parameters
  • x (Any) –

  • y (Any) –

  • scale

Returns

Return type

bool

label(x)

Return scale value corresponding to given number.

Parameters

x (float) –

Returns

Raises

ValueError – if x is outside scale

Return type

Any

static normal()

Return normal scale.

Returns

Return type

QuantitativeScale

property numeric: QuantitativeScale

Return corresponding numeric scale.

range(nb=None)

Return range of value from scale.

Parameters

nb (Optional[int]) – number of values to return

Returns

Return type

List

value(x)

Return corresponding numeric value.

Parameters

x (Any) –

Returns

Raises

ValueError – if x is outside scale

Return type

float

common_scale_type(scale_types)

Determine common type between scale types.

Parameters

scale_types (List[Type[S]]) –

Returns

common scale type

Return type

Type[S]