Sub topic 6
Building a map from attribute ratings with PCA
This chapter assumes you have already chosen a competitor set and a short attribute list, and that you have collected customer ratings on a 1–7 scale. It also assumes basic Python and pandas. You don't need linear algebra, but you should know what a correlation is.
What PCA does for a perceptual map
Your ratings table has one row per brand and one column per attribute. With four attributes, each brand is a point in four-dimensional space, which you can't draw. Principal component analysis (PCA) is a method that finds new axes, called components, built from weighted mixes of the original attributes. The first component points along the direction in which the brands differ most. The second component points along the direction of the next largest difference, at a right angle to the first.
If the first two components capture most of the variation, you can plot brands on those two axes and lose little information. The distance between two brands on the map then approximates how differently customers rate them across all attributes.
Preparing the ratings table
Use the mean rating per brand and attribute, with brands as rows and attributes as columns. Check these points before you run anything:
- Same direction for every attribute. If you asked "how unreliable is this brand?" on one item, reverse-code it (8 minus the rating on a 1–7 scale) so that higher always means "more of the named quality".
- No missing cells. PCA in scikit-learn cannot handle NaN values. Compute the means from complete data or drop the attribute.
- Attributes that measure different things. Two near-duplicate attributes, such as "premium" and "high-end", count twice and pull the first component toward that theme. Merge or remove duplicates during attribute selection.
Why you standardize first
PCA looks for directions of maximum variance. An attribute whose brand averages spread widely would dominate the result, even if that spread only reflects how the question was worded. Standardizing rescales each column to mean 0 and standard deviation 1, so every attribute gets equal influence. This makes PCA work on the correlation structure of the attributes.
Skip standardizing only when all attributes share one scale and you want wide spreads to count for more. That is rare in brand work, so standardize by default.
Running PCA
This code standardizes the ratings, fits two components, and prints brand coordinates, attribute loadings, and the share of variance each component explains.
import pandas as pd
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
# Mean customer ratings (1-7 scale), one row per brand.
ratings = pd.DataFrame(
{
"affordable": [6.1, 5.4, 2.3, 3.0, 4.2],
"premium": [2.0, 3.1, 6.4, 5.8, 4.0],
"innovative": [3.2, 5.9, 5.1, 2.5, 4.4],
"reliable": [5.0, 3.3, 5.6, 6.0, 4.1],
},
index=["Brand A", "Brand B", "Brand C", "Brand D", "Brand E"],
)
scaled = StandardScaler().fit_transform(ratings)
pca = PCA(n_components=2)
coords = pd.DataFrame(
pca.fit_transform(scaled), index=ratings.index, columns=["dim1", "dim2"]
)
loadings = pd.DataFrame(
pca.components_.T, index=ratings.columns, columns=["dim1", "dim2"]
)
print(coords.round(2))
print(loadings.round(2))
print(pca.explained_variance_ratio_.round(2))The workflow is the same for any ratings table, as the diagram shows.
Reading the three outputs
Each output answers a different question.
| Output | Shape | What it tells you |
|---|---|---|
| `coords` | brands × components | Where each brand sits on the map |
| `loadings` | attributes × components | Which attributes define each axis |
| `explained_variance_ratio_` | one value per component | How much of the original variation each axis keeps |
Coordinates. A brand at 0 on an axis is average on that dimension. Positive and negative values mean above or below the average brand. The scale is arbitrary, so only relative positions matter.
Loadings. In scikit-learn, components_ holds the weights that combine standardized attributes into a component. An attribute with a large positive weight pushes brands up on that axis, and one with a large negative weight pushes them down. If "affordable" and "premium" have opposite signs of similar size on dim1, you can name that axis "value versus prestige". The next chapter covers naming in detail.
Explained variance. The two ratios sum to the share of information the map keeps. With four standardized attributes the total variance is 4, so a ratio of 0.6 for dim1 means that one axis carries about 2.4 attributes' worth of variation. If the two ratios sum to about 0.8 or more, the map is a faithful summary. If they sum to about 0.5, brands that look close on the map may differ a lot on the hidden dimensions.
Edge cases and gotchas
Signs are arbitrary
A component and its mirror image describe the same structure. Another library version, or one changed input row, can flip dim1 so that "premium" brands move from right to left. Never compare maps from two runs by eye without checking signs. When you need stable output, flip each axis so that a chosen anchor attribute has a positive loading:
for dim in ["dim1", "dim2"]:
if loadings.loc["premium", dim] < 0:
loadings[dim] *= -1
coords[dim] *= -1Pick the anchor once and keep it for every wave of the study.
Few brands limit the dimensions
With n brands, the standardized data has at most n − 1 directions of variation. Five brands give at most four components, and three brands give only two. The example above works, but five points can be fitted nearly perfectly almost by chance. Treat maps with fewer than about six or seven brands as descriptive sketches, not as evidence of structure.
Loadings are weights, not correlations
A weight of 0.5 does not mean a correlation of 0.5. To see how strongly each attribute relates to an axis, correlate the raw ratings with the coordinates:
print(ratings.corrwith(coords["dim1"]).round(2))
print(ratings.corrwith(coords["dim2"]).round(2))Correlations near ±1 mean the attribute almost defines the axis. Values near 0 mean the axis says little about that attribute.
Attributes poorly represented by two axes
An attribute can be important to customers yet have small loadings on both axes, because it varies along a third component. Its arrow on the map will be short. Don't read brand differences on that attribute from the map. Go back to the ratings table.
The halo effect compresses the first component
Respondents often rate a brand they like highly on everything. Brand averages then rise together, and dim1 turns into a general "liked versus disliked" axis. If all loadings on dim1 have the same sign, suspect this. One remedy is to subtract each brand's average across attributes before you standardize. That removes overall liking and leaves the profile shape.
Adding attribute arrows
A biplot shows brands and attributes together. Each attribute becomes an arrow from the origin, pointing in the direction where that attribute's rating is highest. Brands sitting far out along an arrow rate high on that attribute. This code continues from the first block, using its coords, loadings, and pca variables:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 6))
ax.scatter(coords["dim1"], coords["dim2"])
for brand, row in coords.iterrows():
ax.annotate(brand, (row["dim1"], row["dim2"]), xytext=(5, 5), textcoords="offset points")
scale = coords.abs().max().max() # stretch arrows to the brand cloud
for attr, row in loadings.iterrows():
ax.arrow(0, 0, row["dim1"] * scale, row["dim2"] * scale,
color="firebrick", head_width=0.08, length_includes_head=True)
ax.text(row["dim1"] * scale * 1.1, row["dim2"] * scale * 1.1,
attr, color="firebrick")
ax.axhline(0, color="grey", linewidth=0.8)
ax.axvline(0, color="grey", linewidth=0.8)
var = pca.explained_variance_ratio_
ax.set_xlabel(f"Dimension 1 ({var[0]:.0%} of variance)")
ax.set_ylabel(f"Dimension 2 ({var[1]:.0%} of variance)")
ax.set_title("Perceptual map with attribute directions")
plt.show()The arrow scale is for readability only. The lengths do not compare to brand distances, but the angles between arrows are meaningful. Two arrows at a small angle mean the attributes are positively correlated across brands. Arrows pointing in opposite directions mean they trade off. Arrows at right angles mean they are unrelated.
Common errors
| Mistake | Effect | Fix |
|---|---|---|
| Skipping standardization | The widest-spread attribute dominates dim1 | Use `StandardScaler` |
| Mixed rating directions | Opposite meanings cancel | Reverse-code before PCA |
| Reading the coordinate scale as meaningful | Wrong claims about "how far" | Compare only relative positions |
| Naming an axis from one attribute | Misleading axis label | Use all large loadings and the correlations |
| Ignoring the sign flip | Maps look different between runs | Anchor the sign to one attribute |
| Fitting many attributes to few brands | Overfitted, unstable map | Reduce attributes or add brands |
Exercise
A colleague's PCA map has dim1 explaining 48% of the variance and dim2 explaining 14%. All four attribute loadings on dim1 are positive and between 0.45 and 0.55. What does this suggest about dim1, and what could you try?
Show answer
Because every attribute loads positively and about equally, dim1 probably measures a general "rates high on everything" effect, such as a halo effect or overall liking, and not a real trade-off between brand qualities. Subtract each brand's mean rating across attributes before standardizing, or re-examine the survey for halo bias. Then refit and check whether the structure now shows contrasts between attributes. Also note that the two axes cover only 62% of the variance, so check dim3 before trusting the map.
Exercise
You rerun the analysis next quarter and "Brand C" jumps from the far right to the far left of the map. The ratings barely changed. What is the most likely cause, and how do you confirm and prevent it?
Show answer
The axis sign flipped. PCA components are defined only up to sign, so dim1 and its mirror image are equally valid. Confirm by checking whether the loadings on dim1 all changed sign and whether the distances between brands are unchanged. Prevent it by multiplying the axis (coordinates and loadings) by -1 whenever a chosen anchor attribute, such as "premium", has a negative loading, and by keeping the same anchor in every wave.