Data Objects and Attributes

A data set is a collection of data objects (also called records, samples or tuples), and each object is described by attributes (also called features or variables), for example a student object with roll number, marks and grade.

Attribute Types

  • Nominal: names or categories with no order (colour, city).
  • Binary: only two values, 0 or 1 (pass or fail). It may be symmetric or asymmetric.
  • Ordinal: categories with a meaningful order but unknown gaps (small, medium, large).
  • Numeric, interval-scaled: measured on a scale with no true zero (temperature in Celsius).
  • Numeric, ratio-scaled: has a true zero, so ratios make sense (height, salary).

Attributes are also discrete (a finite set of values) or continuous (real numbers).

Measures of Central Tendency

  • Mean: the sum of the values divided by their count.
  • Median: the middle value of the sorted data (the average of the two middle values for an even count).
  • Mode: the most frequent value.

Measures of Dispersion

  • Range: maximum minus minimum.
  • Quartiles: Q1 (25th percentile), Q2 (the median) and Q3 (75th percentile); IQR = Q3 - Q1.
  • Variance and standard deviation: the average squared distance from the mean, and its square root. For a sample the divisor is n - 1.
  • Outliers: values below Q1 - 1.5 x IQR or above Q3 + 1.5 x IQR.
  • The five-number summary (minimum, Q1, median, Q3, maximum) is drawn as a box plot.

Graphic Displays

Histograms, scatter plots, box plots and quantile plots show the shape of the data and the relation between attributes.

Definition: Attribute. A property or characteristic of a data object, such as marks of a student, that takes values of a particular type.

Table 1.5: Attribute types

Type Order Example
Nominal No Blood group, city
Binary No Yes or no
Ordinal Yes Grade A, B, C
Interval Yes, equal gaps Temperature in Celsius
Ratio Yes, true zero Weight, income

Example 1.5: Statistical description of a data set

Problem: The marks of 8 students are 2, 4, 4, 5, 7, 9, 10 and 12. Find the mean, median, mode, range, quartiles, IQR and the sample standard deviation.

Solution:

  1. Mean = (2 + 4 + 4 + 5 + 7 + 9 + 10 + 12) / 8 = 53 / 8 = 6.625.
  2. Median = (5 + 7) / 2 = 6; the mode is 4 (it occurs twice).
  3. Range = 12 - 2 = 10.
  4. Lower half 2, 4, 4, 5 gives Q1 = 4; upper half 7, 9, 10, 12 gives Q3 = 9.5; IQR = 5.5.
  5. Squared deviations sum to 83.875; sample variance = 83.875 / 7 = 11.982; standard deviation = 3.46.

Result: Mean 6.625, median 6, mode 4, range 10, Q1 4, Q3 9.5, IQR 5.5, standard deviation about 3.46.

import statistics as st
data = [2, 4, 4, 5, 7, 9, 10, 12]
n = len(data)
q1 = st.median(data[:n // 2])
q3 = st.median(data[n // 2:])
print("Mean   :", st.mean(data))
print("Median :", st.median(data), " Mode:", st.mode(data))
print("Range  :", max(data) - min(data))
print("Q1, Q3 :", q1, q3, " IQR:", q3 - q1)
print("Std dev:", round(st.stdev(data), 2))
print("Outlier fences:", q1 - 1.5 * (q3 - q1), q3 + 1.5 * (q3 - q1))

Output

Mean   : 6.625
Median : 6.0  Mode: 4
Range  : 10
Q1, Q3 : 4.0 9.5  IQR: 5.5
Std dev: 3.46
Outlier fences: -4.25 17.75

Common mistakes

  • Treating an ordinal attribute as numeric and averaging grades.
  • Using the mean for data with strong outliers instead of the median.
  • Dividing by n instead of n - 1 for a sample variance.
  • Calling temperature in Celsius a ratio attribute.

Key takeaways

  • Attribute types: nominal, binary, ordinal, interval, ratio.
  • Centre: mean, median, mode; spread: range, IQR, variance, standard deviation.
  • Outliers lie beyond Q1 - 1.5 IQR and Q3 + 1.5 IQR.
  • Box plots display the five-number summary.

Practice questions

  1. Which attribute type has a meaningful zero?
  2. How is IQR calculated?
  3. Which measure of centre is least affected by outliers?

Answers to the practice questions

  1. Ratio-scaled.
  2. Q3 minus Q1.
  3. The median.

Sources

  • Official BCA syllabus Data Warehousing and Mining, course code 25BCA406DS03, Unit I