DataGeometry objects (geo)

The DataGeometry object is the hypertools data object class. A geo contains the data, figure handles, and transform functions used to create a plot. Note that this class should not be called directly, but is used by the hyp.plot function to create a plot object.

In this tutorial we will explore the features of a geo and how it may be used.

Import Hypertools

import hypertools as hyp
import seaborn as sb

%matplotlib inline

Load your data

In this case, we have used one of the sample datasets built into the package.

geo = hyp.load('mushrooms')

Plot it

We can plot a geo by calling the plot method

<hypertools.datageometry.DataGeometry at 0x11bcd9080>

Exploring the geo

Hypertools version

The version field contains the version number of hypertools that the geo was generated with.


Data and plot

The data field contains the raw data.
bruises cap-color cap-shape cap-surface gill-attachment gill-color gill-size gill-spacing habitat odor ... ring-type spore-print-color stalk-color-above-ring stalk-color-below-ring stalk-root stalk-shape stalk-surface-above-ring stalk-surface-below-ring veil-color veil-type
0 t n x s f k n c u p ... p k w w e e s s w p
1 t y x s f k b c g a ... p n w w c e s s w p
2 t w b s f n b c m l ... p n w w c e s s w p
3 t w x y f n n c u p ... p k w w e e s s w p
4 f g x s f k b w g n ... e n w w e t s s w p

5 rows × 22 columns

Transformed data

The xform_data field contains the data that have been transformed according to the user-specified normalize, reduce, and align options (in this case, the data was automatically reduced to 3 dimensions for plotting when we called hyp.plot).

[array([[ 1.30060679,  0.29575138, -1.12870127],
        [ 1.36815474, -0.28876648, -1.82066942],
        [ 1.59220727, -0.26813075, -1.66586137],
        [ 0.40863473,  0.12762486, -0.41712925],
        [-0.89420121,  1.72874308,  0.56553812],
        [ 0.38848708,  0.10733461, -0.58634345]])]

Normalize, reduce and align metadata

The reduce, align and normalize fields contain information about the model and parameters used in each of the analyses.

The reduce and align fields contain dictionaries with the model information and the normalize field contains a string.

{'params': {'n_components': 3}, 'model': 'IncrementalPCA'}
{'model': None, 'params': {}}

Plotting axes and animations

The ax and line_ani fields hold the plot axes and the animation setting (in this case None) for plotting, respectively.

To read more about the plot axes and line animation objects and their utility, see the matlplotlib documentation for axes and animations, respectively.

Plotting with geos

You can also generate a new plot (a new geo) from data stored in the geo using geo.plot.

This plotting feature accepts all of the keyword arguments supported by hypertools.plot.

First, let’s plot without making any changes.

<hypertools.datageometry.DataGeometry at 0x11be41588>

Now, let’s change the plot using some keyword arguments.

In the example below, the data are re-transformed using all of the same options as in the original plot, but with the number of dimensions specified by the reduce model set to 2.

geo.plot(ndims = 2)
<hypertools.datageometry.DataGeometry at 0x11c2ddcf8>

Tranforming data using geos

An additional feature afforded by geos is the ability to later analyze other datasets using the same transformations performed on the original data in the geo. That is, whatever normalization, alignment, and reduction parameters were used on the original data in the geo can be quickly and easily applied to any new dataset using a single line of code!

This allows for easy comparison of multiple datasets. Here, we load a built in dataset (the weights dataset) and apply the transform from the geo data to the first element of weights.

weights = hyp.load('weights_avg').get_data()
transformed = geo.transform(weights)

We can use heatmaps to visualized an element of the new data before and after it has been transformed by the same means as the geo data.

ax = sb.heatmap(weights[0])
ax = sb.heatmap(transformed[0])

Saving geos

You can also easily save a geo using The geo will save as a ‘geo’ file, which is a dictionary containing the elements of a data geometry object saved in the hd5 format using deepdish.

To specify the compression type, pass a string to the compression argument, as below. See the deepdish documentation for the full list of compression options:

#'MyGeoFile', compression = 'blosc')