devnotes.

Univariate Analysis

Univariate Analysis

Depending on the number of variables we look at, analysis falls into three groups: univariate, bivariate and multivariate. We start with the simplest one.

Univariate data has observations of only one variable. There is no relationship to explore, so the goal is only to describe that single variable.

What do we measure?

  • Central tendency - the typical value: mean, median, mode.
  • Dispersion - how spread out the values are: range, variance, standard deviation, IQR.
  • Shape - skewness (asymmetry) and kurtosis (heavy tails).
  • Outliers - values far from the rest.
  • Frequency - for categorical data, how often each category appears.

Which plot for which variable?

Variable typeGood plots
Numeric (continuous)histogram, KDE (density) plot, box plot, violin plot
Numeric (discrete)bar plot of counts, dot plot
Categoricalbar chart, count plot, pie chart (few categories only)

Worked example: heights of 7 students

Heights in cm: [164, 167.3, 170, 174.2, 178, 180, 186]

Only one variable - height - is involved.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

heights = np.array([164, 167.3, 170, 174.2, 178, 180, 186])
df = pd.DataFrame({"Height (cm)": heights})

print(df.describe())
print("Skewness:", df["Height (cm)"].skew())

sns.histplot(df["Height (cm)"], bins=5, kde=True, color="skyblue")
plt.title("Univariate Analysis of Height")
plt.show()

Reading the result

  • Mean is about 174.2 cm and the median is 174.2 cm; they are almost equal, so the data is roughly symmetric.
  • Skewness is close to 0, confirming no strong tail.
  • Range = 186 - 164 = 22 cm, a moderate spread for a class.
  • No point lies far from the others, so there are no obvious outliers.

Real-world applications

  • Quality control: measuring the diameter of bolts one feature at a time to make sure they are uniform.
  • Healthcare: studying blood pressure or cholesterol values of patients to spot trends.
  • Education: looking at the distribution of exam marks in a class.
  • Finance: the distribution of daily returns of a single stock.

Advantages and limitations

Advantages

  • Simple and fast to compute.
  • Gives clear summaries and easy visuals.
  • A necessary first look before anything else.

Limitations

  • Cannot show cause-and-effect or relationships.
  • Two very different datasets can share the same mean, so always plot as well as summarise.

Practice

  1. Take the alcohol column of WineQT. Compute mean, median, std and skewness.
  2. Plot a histogram with kde=True. Is it symmetric or skewed?
  3. Plot a box plot. How many points lie beyond the whiskers?
Univariate Analysis | Exploratory Data Analysis | DevNotes