Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

A Data Science Vocabulary for Task Abstraction

DS 2023 | Communicating with Data

Overview

This notebook attempts to develop a vocabulary of primitive action terms specifically designed for data science.

To motivate this, consider that throughout this course, we have seen that every visualization is produced by two kinds of work:

  • First, you shape and summarize the source data until it has the form the chart needs.

  • Second, you map the data onto on the visual elements of a canvas — marks, scales, facets, labels, etc. — according to a visual metaphor to represent aspects of the data.

These two kinds of work have their own vocabularies:

  • The data mutation words describe what you do to a table.

  • The visual composition words describe what you do to a figure.

These two vocabularies help you plan your code before you write it.

  • They map onto the specific action level of the Visualization Task Hierarchy.

  • Each verb can be used to compose action + target statements.

The Visualization Task Hierarchy

Let’s review the place of these vocabularies in the task abstraction process.

Here is a summary of the process, applied to design:

1 Start at the Task level.

  • State the central analytical question the dashboard is meant to answer.

  • This scopes everything below it.

  • This question should be answerable within the scope of your data.

2 Decompose into Sub-tasks.

  • Break the central question into the 3–5 specific questions a user must answer to reach the goal.

  • Each sub-task is a logical unit of the dashboard (a panel, a view, a filter section).

3 Operationalize each sub-task.

  • Rephrase it as a Verb + Object using controlled vocabularies for data and visualization.

4 Map operations to specific actions.

  • Decide what interactive moves (query, filter, zoom, plot) the user needs to perform that operation.

  • These become your widget choices: sliders, dropdowns, linked charts.

5 Ask: what trails does this dashboard support?

  • A trail is a sequence of actions leading to a discovery.

  • If you can’t trace a plausible path from the Task question to an insight using your dashboard’s controls, something is missing.

Analytic Task Taxonomy

Here is a a vocabulary of ten low-level (primitive) analysis tasks that largely capture people’s activities while employing information visualization tools for understanding data.

From Amar, Eagan & Stasko (2005) “Low-Level Components of Analytic Activity in Information Visualization,” IEEE InfoVis 2005.

#TaskDescriptionPro Forma AbstractExamples
1Retrieve ValueGiven a set of specific observations, find the values of variables for those observations.What are the values of variables {X, Y, Z, ...} for observations {A, B, C, ...}?What is the mileage per gallon of the Audi TT? How long is the movie Gone with the Wind?
2FilterGiven some concrete conditions on variable values, find observations satisfying those conditions.Which observations satisfy conditions {A, B, C, ...}?What Kellogg’s cereals have high fiber? What comedies have won awards? Which funds underperformed the SP-500?
3Compute Derived ValueGiven a set of observations, compute an aggregate numeric representation of those observations.What is the value of aggregation function F over a given set S of observations?What is the average calorie content of Post cereals? What is the gross income of all stores combined? How many manufacturers of cars are there?
4Find ExtremumFind observations possessing an extreme value of a variable over its range within the data set.What are the top/bottom N observations with respect to variable A?What is the car with the highest MPG? What director/film has won the most awards? What Robin Williams film has the most recent release date?
5SortGiven a set of observations, rank them according to some ordinal metric.What is the sorted order of a set S of observations according to their value of variable A?Order the cars by weight. Rank the cereals by calories.
6Determine RangeGiven a set of observations and a variable of interest, find the span of values within the set.What is the range of values of variable A in a set S of observations?What is the range of film lengths? What is the range of car horsepowers? What actresses are in the data set?
7Characterize DistributionGiven a set of observations and a quantitative variable of interest, characterize the distribution of that variable’s values over the set.What is the distribution of values of variable A in a set S of observations?What is the distribution of carbohydrates in cereals? What is the age distribution of shoppers?
8Find AnomaliesIdentify any anomalies within a given set of observations with respect to a given relationship or expectation, e.g. statistical outliers.Which observations in a set S have unexpected/exceptional values?Are there exceptions to the relationship between horsepower and acceleration? Are there any outliers in protein?
9ClusterGiven a set of observations, find clusters of similar variable values.Which observations in a set S are similar in value for variables {X, Y, Z, ...}?Are there groups of cereals with similar fat/calories/sugar? Is there a cluster of typical film lengths?
10CorrelateGiven a set of observations and two variables, determine useful relationships between the values of those variables.What is the correlation between variables X and Y over a given set S of observations?Is there a correlation between carbohydrates and fat? Is there a correlation between country of origin and MPG? Do different genders have a preferred payment method? Is there a trend of increasing film length over the years?

Our own vocabulary

We will create our own vocabulary by abstracting form the tools we have used in this course.

The two verb domains

DomainQuestion it answersTypical tool
Data MutationWhat does the table need to look like?pandas
Visual CompositionWhat does the figure need to show?Seaborn / Matplotlib

A useful rule of thumb:

  • If you are touching a DataFrame, you are in the data mutation domain.

  • If you are touching an Axes or calling a Seaborn function, you are in the visual composition domain.

Many visualization bugs come from mixing the two — trying to fix a chart problem with a data fix, or the reverse. Naming the domain first points you at the right tool.

Data Mutation Verbs

These verbs operate on a DataFrame. They produce another DataFrame (or a scalar summary). They do not care about colors, axes, or marks.

The examples in this section use the penguins dataset from Seaborn. It records body measurements for 344 penguins across three species (Adelie, Chinstrap, Gentoo) on three Antarctic islands. Columns include species, island, bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g, and sex.

Loading...

Declare

Establish an attribute and its measurement scale.

Every column has a dtype that encodes its scale of measurement: float64 for quantitative, category for nominal or ordinal, datetime64 for temporal. Pandas infers dtypes on load, but sometimes you need to declare them explicitly.

The astype() method is the most direct way to do this.

category

Mutate

Compute a new column from existing ones.

Use df.assign() to add derived columns without modifying the original DataFrame. The new column is a function of existing columns.

Loading...

Filter

Restrict rows to those satisfying a predicate.

Boolean indexing selects rows where the condition is True. The result is a smaller DataFrame with the same columns.

124 rows after filtering to Gentoo
Loading...

Sort

Reorder rows by one or more attribute values.

Use sort_values(). Pass ascending=False to sort from largest to smallest.

Loading...

Select

Select a subset of columns.

Projection reduces the table to only the attributes you need. Pass a list of column names to df[[...]].

Loading...

Aggregate

Collapse rows into summary statistics.

groupby().agg() groups rows by one or more columns and applies an aggregation function — mean, median, count, sum, or a custom function — to each group.

Loading...

Pivot

Change the layout of the table.

pivot_table() rotates one column’s values into new column headers. This produces “wide” data, where each category gets its own column. Wide data is convenient for certain chart types and for side-by-side comparisons.

Loading...

Combine

Combine two datasets on a shared key.

pd.merge(), pd.join(), and pd.concat(axis=1) combine DataFrames by matching rows on one or more key columns.

Loading...

Visual Composition Verbs

These verbs operate on a figure or axes object. They assume the data is already in the correct shape. They do not touch the DataFrame.

Map

Map a data attribute to a visual channel.

A visual channel is any perceptual dimension that can carry information: position (xx, yy), color, size, shape, opacity. In Seaborn, bindings are declared as keyword arguments: x=, y=, hue=, size=, style=.

The cell below binds bill_length_mm to the xx-axis, body_mass_g to the yy-axis, and species to color (hue).

<Figure size 700x500 with 1 Axes>

Scale

Define the transformation between the data domain and the visual range.

By default, Matplotlib uses a linear scale. A log scale compresses large ranges; a categorical scale spaces discrete values evenly. Color scales (palettes) map a data range onto a sequence of hues or shades.

<Figure size 1000x300 with 2 Axes>

Draw

Instantiate a geometric mark.

A mark is the basic visual unit: a point, a bar, a line, an area. Choosing a mark is choosing how each row of data appears on the canvas. Seaborn’s named plot functions (scatterplot, barplot, lineplot) each render a different mark type.

<Figure size 1200x300 with 3 Axes>

Transform (Statistical)

Compute a visualization-specific summary on the fly.

Some chart functions bin continuous values, smooth a curve, or compute a confidence interval as part of the rendering step — not as a separate data step. This is a statistical transform built into the visual layer.

  • sns.histplot() bins raw values into counts.

  • sns.regplot() fits and draws a regression line with a confidence band.

<Figure size 1000x500 with 2 Axes>

Subplot

Split the canvas into sub-plots by a categorical attribute.

Faceting creates one panel per category value. It lets you compare the same chart across groups without overlapping marks. In Seaborn, the col= or row= arguments to sns.relplot() and sns.displot() handle faceting.

<Figure size 810x300 with 3 Axes>

Layer

Superimpose multiple geometric marks on the same axes.

Layering adds information density without adding panels. In Matplotlib, you layer by making multiple plot calls on the same ax object.

<Figure size 700x400 with 1 Axes>

Annotate

Add non-data marks: titles, labels, reference lines, text.

Annotation does not encode new data — it explains or contextualizes what is already shown. Use ax.set_title(), ax.set_xlabel(), ax.axhline(), ax.axvline(), and ax.text().

<Figure size 700x500 with 1 Axes>

Worked Example: Verb Chain from Question to Plot

Let’s walk through a complete verb chain — from a plain analytical question to a finished visualization — naming each verb as we apply it.

The Question

Do heavier penguins have proportionally longer bills, and does this differ by species?

The Verb Chain

Data mutation steps:

  1. Filter — drop rows with missing values so every downstream step has clean input.

  2. Mutate — compute bill_ratio (bill length ÷ bill depth) as the “proportionality” measure.

  3. Aggregate — compute the mean bill_ratio and mean body_mass_g per species, to add a per-species summary layer.

Visual composition steps:

  1. Map — map body_mass_g → xx, bill_ratio → yy, species → color.

  2. Draw — draw a scatter mark for the individual penguins.

  3. Layer — superimpose per-species mean points as larger markers.

  4. Annotate — add a title and axis labels.

Let’s execute each step.

333 rows after filtering
Loading...
<Figure size 800x500 with 1 Axes>

Summary

Visualization action verbs and their pandas / Seaborn counterparts

DomainVerbWhat it doesPandas / Seaborn
Data MutationDeclareSet a column’s dtype and measurement scaleastype()
Data MutationMutateCompute a new column from existing onesassign()
Data MutationFilterKeep rows that satisfy a predicatedf[condition], .query()
Data MutationSortReorder rows by attribute valuesort_values()
Data MutationSelectSelect a subset of columnsdf[['a', 'b']]
Data MutationAggregateCollapse rows into summariesgroupby().agg()
Data MutationPivotChange the table layoutpivot_table(), melt()
Data MutationCombineMerge datasets on a shared keypd.merge()
Visual CompositionMapAssign a data attribute to a visual channelx=, y=, hue=, size=
Visual CompositionScaleSet the data-to-visual-range transformationset_xscale(), color palettes
Visual CompositionDrawInstantiate a geometric marksns.scatterplot(), barplot(), lineplot()
Visual CompositionTransform (Statistical)Compute summaries inside the visual layersns.histplot(), sns.regplot()
Visual CompositionFacetSplit into sub-plots by categorycol=, row=, FacetGrid
Visual CompositionLayerSuperimpose marks on the same axesMultiple calls on the same ax
Visual CompositionAnnotateAdd titles, labels, reference marksset_title(), axhline(), text()