A Dataset Description

Here is a brief description of the datasets that are used in this book.

A.1 Boston housing

In repo as boston.csv.bz2

This is a popular dataset for machine learning, available from various sources. The version here is copied from R’s MASS package, but it is identical to other versions. It has 506 rows, 14 numeric variables and no missings. Each row contains data for one neighborhood (town/tract) around Boston. The central variable to be analyzed is typically medv, the median value of single-family homes in that neighborhood. Variables:

  • crim: per capita crime rate by town
  • zn: proportion of residential land zoned for lots over 25,000 sq.ft.
  • indus: proportion of non-retail business acres per town
  • chas: Charles River dummy variable (= 1 if tract bounds river; 0 otherwise)
  • nox: nitrogen oxides concentration (parts per 10 million)
  • rm: average number of rooms per dwelling
  • age: proportion of owner-occupied units built prior to 1940
  • dis: weighted mean of distances to five Boston employment centres
  • rad: index of accessibility to radial highways
  • tax: full-value property-tax rate per $10,000
  • ptratio: pupil-teacher ratio by town
  • black: \(1000(B_k - 0.63)^2\) where \(B_k\) is the proportion of Black residents by town
  • lstat: lower status population (percent)
  • medv: median value of owner-occupied homes in $1000s

Example:

boston <- read_delim("../data/boston.csv.bz2")
boston %>%
   sample_n(4)
## # A tibble: 4 × 14
##     crim    zn indus  chas   nox    rm   age   dis   rad   tax
##    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1  4.87      0 18.1      0 0.614  6.48  93.6  2.31    24   666
## 2 10.8       0 18.1      0 0.679  6.78  90.8  1.82    24   666
## 3  0.323     0 21.9      0 0.624  5.94  93.5  1.97     4   437
## 4  0.762    20  3.97     0 0.647  5.56  62.8  1.99     5   264
## # ℹ 4 more variables: ptratio <dbl>, black <dbl>, lstat <dbl>,
## #   medv <dbl>

A.2 House votes

In repo as house-votes-84.csv.bz2

Voting behavior of 435 representatives of the U.S. House. The data is from 1984 and contains votes for 16 bills. Columns do not have names, but they are:

  • column 1: party (republican/democrat)
  • columns 2-17: vote for 16 different bills. Values are “y” for year, “n” for nay and “?” if neither year nor nay was registered.

It is typically used for predicting party based on the voting behavior.

Example:

read_delim("../data/house-votes-84.csv.bz2",
           col_names = FALSE) %>%
   sample_n(4)
## # A tibble: 4 × 17
##   X1         X2    X3    X4    X5    X6    X7    X8    X9    X10  
##   <chr>      <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 republican n     ?     n     y     y     y     n     n     n    
## 2 democrat   y     n     y     n     n     n     y     y     y    
## 3 democrat   n     n     y     n     y     y     n     n     n    
## 4 republican y     n     y     y     n     n     n     y     y    
## # ℹ 7 more variables: X11 <chr>, X12 <chr>, X13 <chr>, X14 <chr>,
## #   X15 <chr>, X16 <chr>, X17 <chr>

A.3 Hubble

In repo as hubble.csv

Distance and radial velocity data data of 24 galaxies from the 1929 publication by E. Hubble A Relation Between Distance And Radial Velocity Among Extra-Galactic Nebulae, Proceedings of the National Academy of Sciences, 1929, 15, 168-173.

Variables are
  • object: name of the galaxy
  • ms: magnitude (brightness) of brightest stars in that galaxy. Magnitude of a few closest objects are denoted by “..”, this is so even in the original paper.
  • R: distance (Mpc)
  • v: radial velocity (km/s), negative values are toward us
  • mt: visual magnitude (brightness)
  • Mt: absolute magnitude
  • D
  • Rmodern: modern distance estimate (km/s)
  • vModern: modern radial velocity estimate (km/s)

The modern estimates are obtained from wikipedia.

Data example:

hubble <- read_delim("../data/hubble.csv")
hubble %>%
   sample_n(4)
## # A tibble: 4 × 9
##   object ms        R     v    mt    Mt     D Rmodern vModern
##   <chr>  <chr> <dbl> <dbl> <dbl> <dbl> <dbl>   <dbl>   <dbl>
## 1 4214   18.3    0.8   300  11.3 -13.2  0.79    3.1    291  
## 2 1068   18.7    1     920   9.1 -15.9  1      14.4   1137  
## 3 3031   18.5    0.9   -30   8.3 -16.4  0.87    3.68   -33.9
## 4 4486   ..      2     800   9.7 -16.8  2      16.4   1284

Hubble diagram, based on his 1929 data.

The data was used for the famous Hubble diagram (Figure 1 in the 1929 paper):

hubble %>%
   ggplot(aes(R, v)) +
   geom_point(size = 2) +
   geom_smooth(method = "lm",
               se = FALSE)

(The original figure corrects for solar motion though.)

A.4 Iris

Virginica flower. The image shows large sepals and smaller petals. Sepals typically function as support and cover for flowers in bud and are green, while petals are brightly colored to attract pollinators. Iris flowers, however, have both types of leaves colored in a similar fashion.

Source: Eric Hunt, CC BY-SA 4.0, via Wikimedia Commons.

Iris dataset is collected by Ronald Fisher 1936. It contains sepal and petal measures (see the figure for explanation) of 150 iris flowers of three species–setosa, versicolor and virginica (50 of each).

It is an R built-in dataset and can be loaded with

data(iris)

The variables are

  • Sepal.Length: sepal length, in cm
  • Sepal.Width
  • Petal.Length
  • Petal.Width
  • Species: setosa/versicolor/virginica

The widths and lengths are measured with precision of one millimeter, and hence there are quite a few overlapping values.

Data example:

iris %>%
   sample_n(4)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
## 1          5.1         2.5          3.0         1.1 versicolor
## 2          5.0         2.0          3.5         1.0 versicolor
## 3          5.6         3.0          4.5         1.5 versicolor
## 4          5.2         4.1          1.5         0.1     setosa

A.5 Orange trees

In repo as orange-trees.csv

Orange tree size (circumference) as a function of age for five different trees.

This is a version of R built-in dataset Orange. However, it is stored as csv file in order to enforce the tree id to be an integer.

Variables:

  • tree: tree id (1-5)
  • age: in days (days since 1968/12/31)
  • circumference: trunk circumferences (mm). This is probably “circumference at breast height”, a standard measurement in forestry.

Data example:

orange <- read_delim("../data/orange-trees.csv")
orange %>%
   slice(c(1,2, 8,9))
## # A tibble: 4 × 3
##    tree   age circumference
##   <dbl> <dbl>         <dbl>
## 1     1   118            30
## 2     1   484            58
## 3     2   118            33
## 4     2   484            69

A.6 Titanic

In repo as titanic.csv.bz2.

List of RMS Titanic passengers, their name, age and some more data, and whether they survived the shipwreck. It was collected by the investigation committee, and contains most of the passengers on the boat. The dataset is available in various sources, e.g. at kaggle. The variables are

  • pclass Passenger Class (1 = 1st; 2 = 2nd; 3 = 3rd)
  • survived Survival (0 = No; 1 = Yes)
  • name Name
  • sex Sex
  • age Age
  • sibsp Number of Siblings/Spouses Aboard
  • parch Number of Parents/Children Aboard
  • ticket Ticket Number
  • fare Passenger Fare
  • cabin Cabin
  • embarked Port of Embarkation (C = Cherbourg; Q = Queenstown; S = Southampton)
  • boat Lifeboat code (if survived)
  • body Body number (if did not survive and body was recovered)
  • home.dest The home/final destination of passenger

Example:

titanic <- read_delim("../data/titanic.csv.bz2")
titanic %>%
   sample_n(4)
## # A tibble: 4 × 14
##   pclass survived name  sex     age sibsp parch ticket  fare cabin
##    <dbl>    <dbl> <chr> <chr> <dbl> <dbl> <dbl> <chr>  <dbl> <chr>
## 1      2        1 "She… fema…    25     0     1 230433  26   <NA> 
## 2      2        1 "Ham… fema…    24     0     2 250649  14.5 <NA> 
## 3      2        0 "McC… male     32     0     0 237216  13.5 <NA> 
## 4      2        0 "Fro… male     NA     0     0 239854   0   <NA> 
## # ℹ 4 more variables: embarked <chr>, boat <chr>, body <dbl>,
## #   home.dest <chr>

A.7 Treatment

In repo as treatment.csv.bz2. Originates from R package Ecdat. A U.S. dataset from 1974, used for evaluating treatment effect of training on earnings.

  • treat: treated, participated in the job training program (TRUE/FALSE)
  • age: age
  • educ: education in years
  • ethn: three categories: “other”, “black”, “hispanic”
  • married: married (TRUE/FALSE)
  • re74: real annual earnings in 1974 (USD, pre-treatment)
  • re75: real annual earnings in 1975 (USD, pre-treatment)
  • re78: real annual earnings in 1978 (USD, post-treatment)
  • u74: unemployed in 1974 (TRUE/FALSE)
  • u75: unemployed in 1975 (TRUE/FALSE)

Example

treatment <- read_delim("../data/treatment.csv.bz2")
treatment %>%
   sample_n(5)
## # A tibble: 5 × 10
##   treat   age  educ ethn  married   re74   re75   re78 u74   u75  
##   <lgl> <dbl> <dbl> <chr> <lgl>    <dbl>  <dbl>  <dbl> <lgl> <lgl>
## 1 FALSE    21     8 black FALSE       0    895.  2305. FALSE TRUE 
## 2 FALSE    46    12 black TRUE    29389  30436. 22166. FALSE FALSE
## 3 FALSE    40    16 other TRUE    43104. 39387. 45810. FALSE FALSE
## 4 FALSE    27    15 other TRUE     3723.  4655. 19210. FALSE FALSE
## 5 FALSE    43    10 other TRUE     5878. 17903. 20688. FALSE FALSE

A.8 Yin-yang

Classes 0 and 1 plotted with different colors/symbols on the plane.

In repo as yin-yang.csv.bz2 Artifical dataset to demonstrate decision boundary for classification methods. Contains two categories, separated by a wavy pattern, broadly resembling the yin-yang symbol. Columns:
  • x, y: location on plane (both between about -3 and 3)
  • c: category, 0/1

Example:

yinyang %>%
   head(4)
## # A tibble: 4 × 3
##        x      y c    
##    <dbl>  <dbl> <fct>
## 1 -1.63   0.584 0    
## 2  0.624 -0.113 0    
## 3 -0.688  1.74  1    
## 4  0.391  1.13  1