0Pricing
Learn AI with Python · Lesson

Bivariate and Multivariate Analysis

Scatter plots, pair plots, correlation heatmaps, grouped statistics.

Bivariate and Multivariate Analysis is a free Learn AI with Python lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

From One Variable to Many

Bivariate analysis studies the relationship between two variables; multivariate analysis looks at several at once.

The goal: find which features move together, spot interactions, and decide which variables are predictive of your target.

Scatter Plots with plt.scatter

A scatter plot plots two numeric variables against each other — each dot is one row. It reveals trends, clusters, and outliers.

import matplotlib.pyplot as plt
import seaborn as sns

plt.scatter(df["height"], df["weight"], alpha=0.4)
plt.xlabel("Height")
plt.ylabel("Weight")
plt.show()

Reading a Scatter Plot

Look for the direction (upward = positive relationship, downward = negative), the strength (tight band vs scattered cloud), and the shape (linear vs curved).

Add a hue with sns.scatterplot to color points by a category and reveal group structure.

sns.scatterplot(x="height", y="weight", hue="gender", data=df, alpha=0.5)
plt.show()

Correlation with df.corr()

df.corr() computes the pairwise Pearson correlation between numeric columns: a number from -1 to +1.

  • +1 → perfect positive linear relationship
  • 0 → no linear relationship
  • -1 → perfect negative
corr = df.corr(numeric_only=True)
print(corr["price"].sort_values(ascending=False))

Correlation Heatmaps

A correlation matrix is easier to read as a heatmap. Pass annot=True to print the values inside each cell.

Use a diverging colormap (e.g. coolwarm) so positive and negative correlations get distinct colors.

corr = df.corr(numeric_only=True)
sns.heatmap(corr, annot=True, fmt=".2f", cmap="coolwarm", center=0)
plt.show()

Spotting Multicollinearity

When two features have very high correlation (e.g. > 0.9), they carry redundant information. This is multicollinearity, which can destabilize linear models.

The heatmap makes redundant pairs jump out so you can drop one of them.

corr = df.corr(numeric_only=True).abs()
high = corr[(corr > 0.9) & (corr < 1.0)]
print(high.dropna(how="all"))

Correlation Is Not Causation

A strong correlation does not mean one variable causes the other. Both could be driven by a hidden third variable, or the link could be coincidence.

Use correlation to generate hypotheses, then validate with domain knowledge and controlled analysis.

Pair Plots with sns.pairplot

sns.pairplot draws a grid of scatter plots for every pair of numeric columns, with histograms or KDEs on the diagonal.

It is the fastest way to eyeball all bivariate relationships at once. Limit columns on large datasets — it scales as columns squared.

sns.pairplot(df[["height", "weight", "age", "income"]], hue="gender")
plt.show()

Grouped Box Plots

To relate a numeric variable to a categorical one, put the category on the x-axis of a box plot. You instantly compare distributions across groups.

sns.boxplot(x="city", y="income", data=df)
plt.xticks(rotation=45)
plt.show()

Grouped Aggregations

Numbers complement plots. groupby with agg summarizes a numeric column across categories.

This is multivariate analysis in table form — compare means, medians, and counts side by side.

summary = df.groupby("city")["income"].agg(["mean", "median", "count"])
print(summary.sort_values("mean", ascending=False))

Multivariate Plots with Encodings

You can squeeze three or more variables into one chart using visual encodings: x, y, color (hue), and size.

This shows how relationships change across a third dimension without making separate plots.

sns.scatterplot(x="height", y="weight", hue="age", size="income", data=df)
plt.show()

Quick Check: Correlation Range

You run df.corr() and see a value of -0.85 between two features.

Recap: Bivariate and Multivariate Analysis

You can now explore relationships between variables:

  • plt.scatter / sns.scatterplot for two numerics
  • df.corr() + sns.heatmap(annot=True) for the correlation matrix
  • High correlations flag multicollinearity (drop redundant features)
  • sns.pairplot for an all-pairs overview
  • Grouped box plots and groupby().agg() for numeric-vs-categorical

Next we connect features directly to the prediction target.

Frequently asked questions

Is the “Bivariate and Multivariate Analysis” lesson free?

Yes — the full text of “Bivariate and Multivariate Analysis” is free to read here on the web, and the Learn AI with Python course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.

What will I learn in “Bivariate and Multivariate Analysis”?

Scatter plots, pair plots, correlation heatmaps, grouped statistics. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Learn AI with Python?

No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Bivariate and Multivariate Analysis” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Learn AI with Python lesson?

Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. EDA Workflow and Data Profiling
  2. Univariate Analysis
  3. Bivariate and Multivariate Analysis
  4. Feature Distribution and Target Analysis
← Back to Learn AI with Python