flippers.multipolar_to_monopolar#

flippers.multipolar_to_monopolar(L, polarities_mapping={})#

Convert a pandas DataFrame of weak labels in multipolar representation to monopolar representation.

Parameters:
  • L (pd.DataFrame) –

    The input DataFrame of weak labels.

    Each column represents a weak labeler and each row represents a data point.

  • polarities_mapping (Dict[str, List[int]]) –

    A dictionary specifying the possible polarities for each weak labeler.

    The keys are the column names of L and the values are lists of integers representing the possible polarities.

    If not specified, the function will attempt to infer the polarities by examining the unique values in each column of L.

Returns:

A tuple containing the following elements:

  • A pandas DataFrame of monopolar weak labels.

  • A 1D numpy array containing the polarities

  • A dictionary specifying the original polarities for each weak labeler.

The keys are the column names of the input and the values are lists of integers representing the possible polarities.

Return type:

L_monopolar, polarities, polarities_mapping

Example

Its always better to use an hand written polairites_mapping. polarities_mapping lists possible polarities each labeling function can have.

>>> multipolar = pd.DataFrame([[-1, 1, 2], [0, -1, 0], [-1, -1, 2]])
>>> polarities_mapping = {'0': [0], '1': [1], '2': [0, 2]}
>>> L, polarities, _ = flippers.multipolar_to_monopolar(
                                            multipolar, polarities_mapping
                                            )
>>> L
   0  1  2__0  2__2
0  0  1     0     1
1  1  0     1     0
2  0  0     0     1

If you dont want to create the mapping, the function can infer one. This is potentially breaking if multipolar does not contain all possible outputs.

>>> L, polarities, polarities_mapping = flippers.multipolar_to_monopolar(multipolar)
>>> L
   0  1  2__0  2__2
0  0  1     0     1
1  1  0     1     0
2  0  0     0     1
>>> polarities # output L polarities
array([0, 1, 0, 2], dtype=int64)
>>> polarities_mapping # input multipolar polarities
{'0': [0], '1': [1], '2': [0, 2]}