BehaviorAnalyzer.py 708 B

123456789101112131415161718192021222324252627
  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: zsc
  4. @time: 2024/11/18
  5. @desc: 行为分析
  6. """
  7. import time
  8. import random
  9. from collections import defaultdict
  10. import matplotlib.pyplot as plt
  11. # 行为分析模块
  12. class BehaviorAnalyzer:
  13. def __init__(self, data):
  14. self.data = data
  15. def analyze(self):
  16. # 分析用户行为模式,并展示各个指标的统计情况
  17. behavior_count = defaultdict(lambda: defaultdict(int))
  18. action_stats = defaultdict(int)
  19. for item in self.data:
  20. user = item['user']
  21. action = item['action']
  22. behavior_count[user][action] += 1
  23. action_stats[action] += 1
  24. return behavior_count, action_stats