跨文化服饰受众重合度计算程序,分析同时喜欢国风与法式穿搭的消费群体特征。
用 Python 构建跨文化服饰受众重合度计算程序分析同时喜欢国风与法式穿搭的消费群体特征并以中立视角呈现完整分析过程。一、实际应用场景描述在《时尚产业与品牌创新》课程中跨文化风格融合是品牌创新的重要方向。现实中消费者并非非此即彼——大量用户同时喜欢国风东方禅意/新中式和法式浪漫慵懒/effortless chic穿搭。典型场景- 小红书用户收藏了新中式旗袍穿搭笔记同时也点赞法式慵懒风连衣裙内容。- 品牌 DTC 数据同一用户在 3 个月内既购买了汉服元素单品又购买了法式衬衫。- 市场营销如果国风 × 法式受众重合度高达 40%是否可以推出新中式×法式浪漫融合系列品牌面临核心问题喜欢国风的人有多少也喜欢法式他们的年龄、消费力、审美偏好有什么特征这能否支撑一个融合产品线二、引入痛点- 跨风格受众分析多停留在定性描述喜欢国风的女生也可能喜欢法式缺乏量化重合度指标。- 用户画像数据分散在多个平台小红书、抖音、天猫、品牌私域缺乏统一 ID 打通。- 重合度计算停留在简单的韦恩图A ∩ B无法处理多维度受众特征的交叉分析。⇒ 用 Python 构建受众画像数据库 Jaccard 重合度计算 多维特征交叉分析 融合潜力评估模型输出国风×法式受众的完整画像与融合建议。三、核心逻辑讲解1. 受众特征维度设计为每位用户构建多维特征向量维度 子维度 量化方式风格偏好 国风偏好分 / 法式偏好分 0-100基于互动行为人口属性 年龄段 / 城市等级 / 性别 分类变量消费力 年均服饰消费额 万元审美倾向 简约-繁复光谱 / 传统-现代光谱 0-100内容行为 互动频次 / 内容类型偏好 数值 分类2. 重合度计算模型Jaccard 重合度 |A ∩ B| / |A ∪ B|其中A 国风受众集合偏好分 ≥ 阈值B 法式受众集合偏好分 ≥ 阈值扩展加权 Jaccard加权重合度 Σ min(w_i × a_i, w_i × b_i) / Σ max(w_i × a_i, w_i × b_i)其中 w_i 是维度 i 的权重a_i/b_i 是用户在该维度的特征值3. 融合潜力评估融合潜力得分 α × 重合度 β × 消费力均值 γ × 审美兼容度审美兼容度 100 - |国风审美均值 - 法式审美均值|两风格在审美光谱上越接近融合越自然四、代码模块化cross_culture_audience.py#!/usr/bin/env python3# -*- coding: utf-8 -*-cross_culture_audience.py跨文化服饰受众重合度计算程序分析同时喜欢国风与法式穿搭的消费群体特征依赖: numpy, pandas, matplotlib, scipy安装: pip install numpy pandas matplotlib scipyimport numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom matplotlib import rcParamsfrom matplotlib.patches import FancyBboxPatchfrom dataclasses import dataclass, fieldfrom typing import Dict, List, Tuple, Optional, Setfrom enum import Enumfrom collections import Counterfrom scipy.spatial.distance import jaccardrcParams[font.sans-serif] [Noto Sans CJK SC, SimHei, Microsoft YaHei]rcParams[axes.unicode_minus] False# ──────────────────────────────────────────────# 1. 枚举与数据结构# ──────────────────────────────────────────────class StyleType(Enum):服饰风格GUOFENG 国风FRENCH 法式JAPANESE 日系AMERICAN 美式KOREAN 韩系class AgeGroup(Enum):年龄段GEN_Z 18-25岁MILLENIAL 26-35岁GEN_X 36-45岁BOOMER 46-55岁class CityTier(Enum):城市等级TIER_1 一线TIER_2 二线TIER_3 三线TIER_4 四线及以下dataclassclass UserProfile:用户画像user_id: str# 风格偏好0-100基于互动/购买行为推断guofeng_preference: float # 国风偏好french_preference: float # 法式偏好japanese_preference: float # 日系偏好american_preference: float # 美式偏好korean_preference: float # 韩系偏好# 人口属性age_group: AgeGroupcity_tier: CityTiergender: str # 男/女/其他# 消费力annual_fashion_spend: float # 年均服饰消费万元avg_order_value: float # 平均客单价元# 审美倾向0-100 量表minimalism_maximalism: float # 简约←→繁复traditional_modern: float # 传统←→现代practical_artistic: float # 实用←→艺术# 内容行为total_interactions: int # 总互动次数video_views: int # 视频观看数image_saves: int # 图片收藏数post_shares: int # 分享次数# 平台platform: str # 小红书/抖音/微博/品牌私域# ──────────────────────────────────────────────# 2. 用户数据生成模块# ──────────────────────────────────────────────class UserDatabase:模拟用户画像数据库基于时尚消费报告与平台用户画像综合构建staticmethoddef generate_users(n_per_style: int 500,seed: int 42) - List[UserProfile]:生成模拟用户数据n_per_style: 每种风格的核心用户数np.random.seed(seed)users []# ── 国风核心用户 ──for i in range(n_per_style):u UserProfile(user_idfGF_{i:04d},guofeng_preferencenp.random.normal(85, 10),french_preferencenp.random.normal(30, 15),japanese_preferencenp.random.normal(25, 12),american_preferencenp.random.normal(20, 10),korean_preferencenp.random.normal(15, 10),age_groupnp.random.choice([AgeGroup.GEN_Z, AgeGroup.MILLENIAL, AgeGroup.GEN_X],p[0.35, 0.45, 0.20]),city_tiernp.random.choice([CityTier.TIER_1, CityTier.TIER_2, CityTier.TIER_3, CityTier.TIER_4],p[0.30, 0.30, 0.25, 0.15]),gendernp.random.choice([女, 男, 其他], p[0.75, 0.22, 0.03]),annual_fashion_spendround(np.random.normal(2.5, 1.2), 1),avg_order_valueround(np.random.normal(450, 200), 0),minimalism_maximalismnp.random.normal(35, 15), # 偏简约traditional_modernnp.random.normal(25, 12), # 偏传统practical_artisticnp.random.normal(60, 15), # 偏艺术total_interactionsnp.random.randint(50, 500),video_viewsnp.random.randint(20, 300),image_savesnp.random.randint(10, 200),post_sharesnp.random.randint(2, 50),platformnp.random.choice([小红书, 抖音, 微博, 品牌私域],p[0.45, 0.30, 0.15, 0.10]))users.append(u)# ── 法式核心用户 ──for i in range(n_per_style):u UserProfile(user_idfFS_{i:04d},guofeng_preferencenp.random.normal(25, 12),french_preferencenp.random.normal(85, 10),japanese_preferencenp.random.normal(30, 12),american_preferencenp.random.normal(35, 15),korean_preferencenp.random.normal(20, 10),age_groupnp.random.choice([AgeGroup.GEN_Z, AgeGroup.MILLENIAL, AgeGroup.GEN_X],p[0.30, 0.50, 0.20]),city_tiernp.random.choice([CityTier.TIER_1, CityTier.TIER_2, CityTier.TIER_3, CityTier.TIER_4],p[0.40, 0.30, 0.20, 0.10]),gendernp.random.choice([女, 男, 其他], p[0.80, 0.18, 0.02]),annual_fashion_spendround(np.random.normal(3.0, 1.5), 1),avg_order_valueround(np.random.normal(580, 250), 0),minimalism_maximalismnp.random.normal(55, 12), # 中等偏繁复traditional_modernnp.random.normal(60, 10), # 偏现代practical_artisticnp.random.normal(55, 12), # 偏艺术total_interactionsnp.random.randint(60, 600),video_viewsnp.random.randint(30, 400),image_savesnp.random.randint(15, 250),post_sharesnp.random.randint(5, 80),platformnp.random.choice([小红书, 抖音, 微博, 品牌私域],p[0.50, 0.25, 0.15, 0.10]))users.append(u)# ── 日系核心用户 ──for i in range(n_per_style):u UserProfile(user_idfJP_{i:04d},guofeng_preferencenp.random.normal(15, 8),french_preferencenp.random.normal(20, 10),japanese_preferencenp.random.normal(85, 10),american_preferencenp.random.normal(25, 12),korean_preferencenp.random.normal(30, 12),age_groupnp.random.choice([AgeGroup.GEN_Z, AgeGroup.MILLENIAL, AgeGroup.GEN_X],p[0.40, 0.40, 0.20]),city_tiernp.random.choice([CityTier.TIER_1, CityTier.TIER_2, CityTier.TIER_3, CityTier.TIER_4],p[0.35, 0.30, 0.25, 0.10]),gendernp.random.choice([女, 男, 其他], p[0.70, 0.28, 0.02]),annual_fashion_spendround(np.random.normal(2.0, 1.0), 1),avg_order_valueround(np.random.normal(350, 150), 0),minimalism_maximalismnp.random.normal(20, 10), # 极简traditional_modernnp.random.normal(50, 10), # 中间practical_artisticnp.random.normal(50, 12), # 中间total_interactionsnp.random.randint(40, 400),video_viewsnp.random.randint(15, 250),image_savesnp.random.randint(8, 150),post_sharesnp.random.randint(2, 40),platformnp.random.choice([小红书, 抖音, 微博, 品牌私域],p[0.40, 0.30, 0.20, 0.10]))users.append(u)# ── 混合兴趣用户国风法式 双重兴趣── 这是关键群体n_overlap int(n_per_style * 0.3)for i in range(n_overlap):u UserProfile(user_idfOL_{i:04d},guofeng_preferencenp.random.normal(70, 12),french_preferencenp.random.normal(65, 12),japanese_preferencenp.random.normal(20, 10),american_preferencenp.random.normal(25, 10),korean_preferencenp.random.normal(15, 8),age_groupnp.random.choice([AgeGroup.GEN_Z, AgeGroup.MILLENIAL, AgeGroup.GEN_X],p[0.25, 0.55, 0.20]),city_tiernp.random.choice([CityTier.TIER_1, CityTier.TIER_2, CityTier.TIER_3, CityTier.TIER_4],p[0.35, 0.35, 0.20, 0.10]),gendernp.random.choice([女, 男, 其他], p[0.78, 0.20, 0.02]),annual_fashion_spendround(np.random.normal(3.5, 1.5), 1),avg_order_valueround(np.random.normal(550, 250), 0),minimalism_maximalismnp.random.normal(45, 12), # 中间traditional_modernnp.random.normal(45, 12), # 中间practical_artisticnp.random.normal(65, 10), # 偏艺术total_interactionsnp.random.randint(80, 800),video_viewsnp.random.randint(40, 500),image_savesnp.random.randint(20, 300),post_sharesnp.random.randint(5, 100),platformnp.random.choice([小红书, 抖音, 微博, 品牌私域],p[0.55, 0.25, 0.12, 0.08]))users.append(u)# ── 泛时尚用户低偏好广泛浏览──n_casual int(n_per_style * 0.4)for i in range(n_casual):u UserProfile(user_idfCS_{i:04d},guofeng_preferencenp.random.normal(40, 15),french_preferencenp.random.normal(35, 15),japanese_preferencenp.random.normal(30, 12),american_preferencenp.random.normal(35, 15),korean_preferencenp.random.normal(25, 12),age_groupnp.random.choice([AgeGroup.GEN_Z, AgeGroup.MILLENIAL, AgeGroup.GEN_X, AgeGroup.BOOMER],p[0.30, 0.35, 0.25, 0.10]),city_tiernp.random.choice([CityTier.TIER_1, CityTier.TIER_2, CityTier.TIER_3, CityTier.TIER_4],p[0.25, 0.30, 0.28, 0.17]),gendernp.random.choice([女, 男, 其他], p[0.65, 0.32, 0.03]),annual_fashion_spendround(np.random.normal(1.8, 1.0), 1),avg_order_valueround(np.random.normal(320, 150), 0),minimalism_maximalismnp.random.normal(40, 15),traditional_modernnp.random.normal(45, 15),practical_artisticnp.random.normal(50, 15),total_interactionsnp.random.randint(20, 200),video_viewsnp.random.randint(10, 150),image_savesnp.random.randint(5, 80),post_sharesnp.random.randint(1, 20),platformnp.random.choice([小红书, 抖音, 微博, 品牌私域],p[0.40, 0.35, 0.20, 0.05]))users.append(u)# 截断偏好分数到 0-100for u in users:for attr in [guofeng_preference, french_preference,japanese_preference, american_preference, korean_preference]:val getattr(u, attr)setattr(u, attr, max(0, min(100, val)))print(f 总用户数{len(users)})print(f 国风核心{n_per_style} | 法式核心{n_per_style} f| 日系核心{n_per_style})print(f 重叠群体{n_overlap} | 泛时尚{n_casual})return users# ──────────────────────────────────────────────# 3. 重合度计算引擎模块# ──────────────────────────────────────────────class OverlapCalculator:跨文化受众重合度计算引擎支持 Jaccard / 加权 Jaccard / 余弦相似度def __init__(self, users: List[UserProfile]):self.users usersdef _to_dataframe(self) - pd.DataFrame:转为 DataFrame 便于分析rows []for u in self.users:rows.append({user_id: u.user_id,guofeng: u.guofeng_preference,french: u.french_preference,japanese: u.japanese_preference,american: u.american_preference,korean: u.korean_preference,age_group: u.age_group.value,city_tier: u.city_tier.value,gender: u.gender,annual_spend: u.annual_fashion_spend,avg_order: u.avg_order_value,minimalism: u.minimalism_maximalism,traditional: u.traditional_modern,artistic: u.practical_artistic,total_interactions: u.total_interactions,platform: u.platform,user_type: u.user_id[:2] # GF/FS/JP/OL/CS})return pd.DataFrame(rows)def jaccard_overlap(self,style_a: str guofeng,style_b: str french,threshold: float 50.0) - Dict:计算 Jaccard 重合度将用户偏好 ≥ threshold 视为喜欢该风格df self._to_dataframe()set_a set(df[df[style_a] threshold].index)set_b set(df[df[style_b] threshold].index)intersection set_a set_bunion set_a | set_bif len(union) 0:jaccard 0.0else:jaccard len(intersection) / len(union)return {style_a: style_a,style_b: style_b,threshold: threshold,set_a_size: len(set_a),set_b_size: len(set_b),intersection_size: len(intersection),union_size: len(union),jaccard_index: round(jaccard, 4),overlap_percentage: round(jaccard * 100, 2),only_a: len(set_a - set_b),only_b: len(set_b - set_a),}def weighted_jaccard(self,style_a: str guofeng,style_b: str french,weights: Dict[str, float] None) - Dict:加权 Jaccard 重合度考虑多维度特征偏好 消费力 审美if weights is None:weights {preference: 0.50, # 风格偏好权重spend: 0.20, # 消费力权重aesthetic: 0.30 # 审美兼容性权重}df self._to_dataframe()# 构建特征向量vectors_a []vectors_b []for _, row in df.iterrows():# 风格偏好向量5维pref_vec np.array([row[guofeng] / 100, row[french] / 100,row[japanese] / 100, row[american] / 100,row[korean] / 100])# 消费力向量2维spend_vec np.array([min(row[annual_spend] / 5.0, 1.0), # 归一化min(row[avg_order] / 1000.0, 1.0)])# 审美向量3维aesthetic_vec np.array([row[minimalism] / 100,row[traditional] / 100,row[artistic] / 100])# 加权拼接full_vec np.concatenate([pref_vec * weights[preference],spend_vec * weights[spend],aesthetic_vec * weights[aesthetic]])vectors_a.append(full_vec)vectors_b.append(full_vec) # 同一用户比较的是风格间的距离# 计算每对用户的两个风格向量的相似度similarities []for i in range(len(vectors_a)):# 使用余弦相似度dot np.dot(vectors_a[i], vectors_b[i])norm_a np.linalg.norm(vectors_a[i])norm_b np.linalg.norm(vectors_b[i])if norm_a 0 or norm_b 0:sim 0else:sim dot / (norm_a * norm_b)similarities.append(sim)avg_similarity np.mean(similarities)return {style_a: style_a,style_b: style_b,weights: weights,avg_vector_similarity: round(avg_similarity, 4),similarity_std: round(np.std(similarities), 4),high_overlap_users: sum(1 for s in similarities if s 0.7),total_users: len(similarities)}def find_overlap_users(self,style_a: str guofeng,style_a_thresh: float 60,style_b: str french,style_b_thresh: float 60) - pd.DataFrame:找出同时喜欢两种风格的用户df self._to_dataframe()overlap df[(df[style_a] style_a_thresh) (df[style_b] style_b_thresh)]return overlapdef analyze_overlap_profile(self,overlap_df: pd.DataFrame) - Dict:分析重叠群体的画像特征if len(overlap_df) 0:return {count: 0}profile {}# 年龄分布age_dist overlap_df[age_group].value_counts(normalizeTrue) * 100profile[age_distribution] age_dist.to_dict()# 城市等级分布city_dist overlap_df[city_tier].value_counts(normalizeTrue) * 100profile[city_distribution] city_dist.to_dict()# 性别分布gender_dist overlap_df[gender].value_counts(normalizeTrue) * 100profile[gender_distribution] gender_dist.to_dict()# 消费力profile[avg_annual_spend] round(overlap_df[annual_spend].mean(), 2)profile[avg_order_value] round(overlap_df[avg_order].mean(), 0)profile[spend_pctile_75] round(overlap_df[annual_spend].quantile(0.75), 2)# 审美特征profile[avg_minimalism] round(overlap_df[minimalism].mean(), 1)profile[avg_traditional] round(overlap_df[traditional].mean(), 1)profile[avg_artistic] round(overlap_df[artistic].mean(), 1)# 平台分布platform_dist overlap_df[platform].value_counts(normalizeTrue) * 100profile[platform_distribution] platform_dist.to_dict()# 活跃度profile[avg_interactions] round(overlap_df[total_interactions].mean(), 0)# 用户类型分布type_dist overlap_df[user_type].value_counts(normalizeTrue) * 100profile[user_type_distribution] type_dist.to_dict()return profile# ──────────────────────────────────────────────# 4. 融合潜力评估模块# ──────────────────────────────────────────────class FusionPotentialAnalyzer:跨文化融合潜力评估评估国风×法式融合系列的市场可行性def __init__(self, users: List[UserProfile]):self.users usersself.calculator OverlapCalculator(users)def evaluate_fusion_potential(self,style_a: str guofeng,利用AI解决实际问题如果你觉得这个工具好用欢迎关注长安牧笛