Name the GPS k-means areas by their marquee ride
Replace the "Area N" fallbacks with derived names: Kiddieland (lowest mean PC2) plus The Woodies / The Grand Midway / Flying Turns Grove / Giant Wheel Corner, each keyed off the headline ride that lands in the cluster so the labels survive re-clustering as the wait history grows. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -170,8 +170,10 @@ def compute_pca():
|
||||
loadings = loadings.join(meta)
|
||||
|
||||
# Spatial "areas" from GPS alone — k-means on standardized lat/lon, the same
|
||||
# 5 clusters the write-up uses. Label the one whose rides lean most negative
|
||||
# on PC2 as Kiddieland so the colors read in plain English.
|
||||
# 5 clusters the write-up uses. Names are derived, not hard-coded to a
|
||||
# cluster index, so they survive re-clustering as the history grows:
|
||||
# - Kiddieland = the cluster whose rides lean most negative on PC2.
|
||||
# - the rest are named for the marquee ride that lands in each.
|
||||
located = loadings.dropna(subset=["lat", "lon"])
|
||||
if len(located) >= 5:
|
||||
km = KMeans(n_clusters=5, n_init=10, random_state=0).fit_predict(
|
||||
@@ -179,6 +181,13 @@ def compute_pca():
|
||||
area = pd.Series(km, index=located.index)
|
||||
kiddie = loadings.loc[area.index].assign(a=area).groupby("a")["PC2"].mean().idxmin()
|
||||
names = {kiddie: "Kiddieland"}
|
||||
anchors = [("phoenix", "The Woodies"),
|
||||
("impulse", "The Grand Midway"),
|
||||
("flying_turns", "Flying Turns Grove"),
|
||||
("giant_wheel", "Giant Wheel Corner")]
|
||||
for ride, label in anchors:
|
||||
if ride in area.index:
|
||||
names.setdefault(area[ride], label) # don't overwrite Kiddieland
|
||||
loadings["area"] = area.map(lambda a: names.get(a, f"Area {a + 1}"))
|
||||
else:
|
||||
loadings["area"] = "Untagged"
|
||||
|
||||
Reference in New Issue
Block a user