milia.plot.figures.agreement#

Agreement figures: heatmaps, transitions, the drift-versus-noise strip and window sensitivity.

Functions

confusion(draw, pairs[, title])

How often two clusters share a conformal prediction set.

drift(draw, table[, title])

Distance to own and to nearest other centroid over periods.

heatmap(draw, table[, title, value])

Annotated heatmap of a square agreement table.

square(table, row, column, value)

A square table in long form.

strip(draw, groups[, title, ylabel])

Agreement values per comparison, e.g. seed noise against cross-window drift.

transitions(draw, table[, title])

Cluster transitions between two periods.

window(draw, table[, metrics, title])

Metrics against the history window.

milia.plot.figures.agreement.square(table, row, column, value)#

A square table in long form.

Parameters:
  • table (DataFrame) – Square table.

  • row (str) – Name of the row column in the result.

  • column (str) – Name of the column column in the result.

  • value (str) – Name of the value column in the result.

Return type:

DataFrame

Returns:

One row per cell, row and column labels as strings.

Examples

>>> import pandas as pd
>>> square(pd.DataFrame([[1.0, 0.5], [0.5, 1.0]], index=["a", "b"], columns=["a", "b"]), "r", "c", "v").shape
(4, 3)
milia.plot.figures.agreement.heatmap(draw, table, title=None, value='ari')#

Annotated heatmap of a square agreement table.

Parameters:
Returns:

The figure – a lets-plot PlotSpec or a matplotlib Figure, depending on the backend.

Examples

>>> import numpy as np, pandas as pd
>>> from milia.plot.mpl import agreement
>>> table = pd.DataFrame([[1.0, 0.5], [0.5, 1.0]], index=["a", "b"], columns=["a", "b"])
>>> type(agreement.heatmap(table)).__name__
'Figure'
milia.plot.figures.agreement.transitions(draw, table, title=None)#

Cluster transitions between two periods.

Parameters:
Returns:

The figure – a lets-plot PlotSpec or a matplotlib Figure, depending on the backend.

Examples

>>> import numpy as np, pandas as pd
>>> from milia.plot.mpl import agreement
>>> type(agreement.transitions(pd.crosstab([0, 1, 1], [0, 0, 1]))).__name__
'Figure'
milia.plot.figures.agreement.confusion(draw, pairs, title=None)#

How often two clusters share a conformal prediction set.

Parameters:
Returns:

The figure – a lets-plot PlotSpec or a matplotlib Figure, depending on the backend.

Examples

>>> import numpy as np, pandas as pd
>>> from milia.plot.mpl import agreement
>>> type(agreement.confusion(pd.DataFrame({"a": [0], "b": [1], "count": [3]}))).__name__
'Figure'
milia.plot.figures.agreement.strip(draw, groups, title=None, ylabel='ARI')#

Agreement values per comparison, e.g. seed noise against cross-window drift.

Drift is real only where its values sit below the seed-noise values.

Parameters:
Returns:

The figure – a lets-plot PlotSpec or a matplotlib Figure, depending on the backend.

Examples

>>> import numpy as np, pandas as pd
>>> from milia.plot.mpl import agreement
>>> type(agreement.strip({"seeds": [0.9, 0.95], "quarters": [0.4, 0.5]})).__name__
'Figure'
milia.plot.figures.agreement.window(draw, table, metrics=('ari', 'silhouette'), title=None)#

Metrics against the history window.

Parameters:
Returns:

The figure – a lets-plot PlotSpec or a matplotlib Figure, depending on the backend.

Examples

>>> import numpy as np, pandas as pd
>>> from milia.plot.mpl import agreement
>>> table = pd.DataFrame({"window": ["day", "week"], "ari": [0.3, 0.6], "silhouette": [0.2, 0.3]})
>>> type(agreement.window(table)).__name__
'Figure'
milia.plot.figures.agreement.drift(draw, table, title=None)#

Distance to own and to nearest other centroid over periods.

Parameters:
Returns:

The figure – a lets-plot PlotSpec or a matplotlib Figure, depending on the backend.

Examples

>>> import numpy as np, pandas as pd
>>> from milia.plot.mpl import agreement
>>> table = pd.DataFrame({"period": ["q1", "q2"], "own": [1.0, 2.0], "other": [3.0, 1.5]})
>>> type(agreement.drift(table)).__name__
'Figure'