A tour of hyp.load’s data sources

Open in Colab  run this example as a notebook — or grab the .ipynb (also linked at the bottom of the page)

hypertools.load resolves a plain string dataset name against five sources, in order: HyperTools’ own built-in example datasets (used throughout the rest of this gallery), then four third-party sources: scikit-learn’s bundled datasets, seaborn’s example datasets, FiveThirtyEight’s published datasets (explicit 'fivethirtyeight/<slug>' prefix), and Kaggle datasets (explicit 'kaggle/<owner>/<dataset>' prefix, downloaded anonymously via kagglehub – no Kaggle account or API key required). This example tours the four third-party sources, loading one small dataset from each and plotting it in a 2x2 grid: one panel per source.

sklearn: iris, seaborn: penguins, fivethirtyeight: bechdel, kaggle: uciml/iris
sklearn: iris: (150, 5)
seaborn: penguins: (344, 7)
fivethirtyeight: bechdel: (1794, 15)
kaggle: uciml/iris: (150, 6)

# Code source: Contextual Dynamics Laboratory
# License: MIT

import hypertools as hyp

# Three of these four sources (seaborn, FiveThirtyEight, Kaggle) fetch over
# the network at run time. So that a transient outage doesn't abort the whole
# documentation-gallery build, each load is attempted independently and a
# source that can't be reached is simply skipped (with a printed note); the
# grid is drawn from whichever sources succeeded. In normal interactive use
# you would just call ``hyp.load(name)`` directly, as the first line of each
# block below shows.
sources = [
    # (title, loader, optional numeric-only cleanup for plotting)
    ('sklearn: iris', lambda: hyp.load('iris'), None),
    ('seaborn: penguins', lambda: hyp.load('penguins'),
     lambda df: df.select_dtypes('number').dropna()),
    ('fivethirtyeight: bechdel', lambda: hyp.load('fivethirtyeight/bechdel'),
     lambda df: df.select_dtypes('number').dropna()),
    ('kaggle: uciml/iris', lambda: hyp.load('kaggle/uciml/iris'), None),
]

loaded = []
for title, loader, clean in sources:
    try:
        data = loader()
    except Exception as e:  # network/rate-limit/optional-dep hiccup
        print(f"{title}: skipped ({type(e).__name__}: {e})")
        continue
    print(f"{title}: {getattr(data, 'shape', 'loaded')}")
    loaded.append((title, data if clean is None else clean(data)))

# plot each successfully loaded source side by side, colored/reduced
# automatically by hyp.plot. The rows of these tabular datasets are
# unordered samples, so each is drawn as points ('.') rather than as a
# connected line.
#
# These four sources are unrelated domains with different column counts and
# meanings (iris measurements, penguin measurements, Bechdel-test numeric
# columns, ...), so there is no single shared pipeline fit that would make
# sense across them. hyp.plot's panels= draws one dataset per panel and by
# default fits ONE shared pipeline across them, which requires a common
# column space; panel_fit='independent' fits each panel's own pipeline
# instead and draws a grid like this one too. Here we show the
# explicit-axes form, via hyp.subplots (a thin wrapper over plt.subplots
# that pre-sets the 3-D projection and hands back a flat axes array): each
# hyp.plot(..., ax=ax) call fits its own source's pipeline independently.
n = max(len(loaded), 1)
ncols = 2 if n > 1 else 1
nrows = (n + ncols - 1) // ncols
# backend='matplotlib' on the grid and on each call: the axes are
# matplotlib's, and on Colab the default backend would be plotly
fig, axes = hyp.subplots(nrows, ncols, size=[5 * ncols, 5 * nrows],
                         backend='matplotlib')
for ax in axes:
    ax.set_axis_off()  # hide any unused panels
for (title, data), ax in zip(loaded, axes):
    ax.set_axis_on()
    hyp.plot(data, '.', ax=ax, title=title, backend='matplotlib', show=False)
fig.tight_layout()

Total running time of the script: (0 minutes 1.477 seconds)

Gallery generated by Sphinx-Gallery