# -*- coding: utf-8 -*- """ @author: zsc @time: 2024/11/18 @desc: 行为分析 """ import time import random from collections import defaultdict import matplotlib.pyplot as plt # 行为分析模块 class BehaviorAnalyzer: def __init__(self, data): self.data = data def analyze(self): # 分析用户行为模式,并展示各个指标的统计情况 behavior_count = defaultdict(lambda: defaultdict(int)) action_stats = defaultdict(int) for item in self.data: user = item['user'] action = item['action'] behavior_count[user][action] += 1 action_stats[action] += 1 return behavior_count, action_stats