feat: 添加 JD-R 理论分析模块与 SHAP 可解释性分析功能

- 后端新增 JD-R(工作要求-资源)理论维度数据生成,包含工作要求、工作资源、
    个人资源、中介变量共 16 个新特征列
  - 新增 JD-R 分析服务与 API(维度统计、倦怠投入分析、双路径中介分析、
    分组轮廓、风险分布)
  - 新增 SHAP 可解释性分析模块(全局重要性、局部解释、特征交互、依赖图)
  - 预测服务增加风险分类模型加载与概率预测能力
  - 前端新增 JD-R 分析页面(JDRAnalysis.vue),含雷达图、散点图、路径分析等可视化
  - 预测页面增加风险概率展示与 SHAP 特征解释
  - 路由与导航菜单同步更新
This commit is contained in:
shuo
2026-04-04 07:15:46 +08:00
parent eab1a62ffb
commit e8235bf3ca
30 changed files with 6302 additions and 10 deletions

View File

@@ -35,6 +35,11 @@ NUMERICAL_OUTLIER_COLUMNS = [
'BMI',
'近30天睡眠时长均值',
'每周运动频次',
# JD-R 维度列
'工作自主性', '情绪劳动强度', '时间压力感知', '角色模糊度', '工作家庭冲突',
'上级支持', '同事支持', '技能多样性', '职业发展机会', '参与决策', '组织公平感',
'自我效能感', '心理韧性', '乐观程度',
'工作倦怠', '工作投入',
]
DEFAULT_PREDICTION_INPUT = {
'industry': '制造业',
@@ -82,6 +87,26 @@ DEFAULT_PREDICTION_INPUT = {
'urgent_leave_flag': 1,
'continuous_absence_flag': 0,
'previous_day_overtime_flag': 1,
# JD-R 工作要求维度
'work_autonomy': 3.0,
'emotional_labor': 3.0,
'time_pressure': 3.0,
'role_ambiguity': 3.0,
'work_family_conflict': 3.0,
# JD-R 工作资源维度
'supervisor_support': 3.0,
'coworker_support': 3.0,
'skill_variety': 3.0,
'career_development': 3.0,
'decision_participation': 3.0,
'organizational_justice': 3.0,
# JD-R 个人资源维度
'self_efficacy': 3.0,
'resilience': 3.0,
'optimism': 3.0,
# JD-R 中介变量
'burnout': 3.5,
'work_engagement': 3.5,
}
@@ -171,6 +196,50 @@ def engineer_features(df):
)
df['管理负荷指数'] = df['团队人数'] * 0.4 + df['直属上级管理跨度'] * 0.25
# ── JD-R 复合指数 ──
autonomy = df.get('工作自主性', pd.Series(3.0, index=df.index))
df['工作要求指数'] = (
df['月均加班时长'] * 0.20
+ df['通勤时长分钟'] * 0.08
+ df['是否夜班岗位'] * 1.5
+ (5 - autonomy) * 0.3
+ df.get('情绪劳动强度', pd.Series(3.0, index=df.index)) * 0.25
+ df.get('时间压力感知', pd.Series(3.0, index=df.index)) * 0.25
+ df.get('角色模糊度', pd.Series(3.0, index=df.index)) * 0.20
+ df.get('工作家庭冲突', pd.Series(3.0, index=df.index)) * 0.20
) / 2
df['工作资源指数'] = (
autonomy * 0.18
+ df.get('上级支持', pd.Series(3.0, index=df.index)) * 0.18
+ df.get('同事支持', pd.Series(3.0, index=df.index)) * 0.14
+ df.get('技能多样性', pd.Series(3.0, index=df.index)) * 0.14
+ df.get('职业发展机会', pd.Series(3.0, index=df.index)) * 0.14
+ df.get('参与决策', pd.Series(3.0, index=df.index)) * 0.10
+ df.get('组织公平感', pd.Series(3.0, index=df.index)) * 0.12
)
df['个人资源指数'] = (
df.get('自我效能感', pd.Series(3.0, index=df.index)) * 0.35
+ df.get('心理韧性', pd.Series(3.0, index=df.index)) * 0.35
+ df.get('乐观程度', pd.Series(3.0, index=df.index)) * 0.30
)
df['JD-R平衡度'] = df['工作资源指数'] - df['工作要求指数'] * 0.5
df['倦怠风险指数'] = (
df.get('工作倦怠', pd.Series(3.5, index=df.index)) * 0.40
+ df['工作要求指数'] * 0.30
- df['工作资源指数'] * 0.20
- df['个人资源指数'] * 0.10
)
df['工作投入指数'] = (
df.get('工作投入', pd.Series(3.5, index=df.index)) * 0.40
+ df['工作资源指数'] * 0.30
+ df['个人资源指数'] * 0.30
)
df['工龄分层'] = pd.cut(df['司龄年数'], bins=[0, 2, 5, 10, 40], labels=['1', '2', '3', '4'])
df['年龄分层'] = pd.cut(df['年龄'], bins=[18, 25, 32, 40, 60], labels=['1', '2', '3', '4'])
df['通勤分层'] = pd.cut(df['通勤时长分钟'], bins=[0, 25, 45, 70, 180], labels=['1', '2', '3', '4'])
@@ -299,6 +368,26 @@ def build_prediction_dataframe(data):
'previous_day_overtime_flag',
DEFAULT_PREDICTION_INPUT['previous_day_overtime_flag'],
),
# JD-R 工作要求维度
'工作自主性': data.get('work_autonomy', DEFAULT_PREDICTION_INPUT['work_autonomy']),
'情绪劳动强度': data.get('emotional_labor', DEFAULT_PREDICTION_INPUT['emotional_labor']),
'时间压力感知': data.get('time_pressure', DEFAULT_PREDICTION_INPUT['time_pressure']),
'角色模糊度': data.get('role_ambiguity', DEFAULT_PREDICTION_INPUT['role_ambiguity']),
'工作家庭冲突': data.get('work_family_conflict', DEFAULT_PREDICTION_INPUT['work_family_conflict']),
# JD-R 工作资源维度
'上级支持': data.get('supervisor_support', DEFAULT_PREDICTION_INPUT['supervisor_support']),
'同事支持': data.get('coworker_support', DEFAULT_PREDICTION_INPUT['coworker_support']),
'技能多样性': data.get('skill_variety', DEFAULT_PREDICTION_INPUT['skill_variety']),
'职业发展机会': data.get('career_development', DEFAULT_PREDICTION_INPUT['career_development']),
'参与决策': data.get('decision_participation', DEFAULT_PREDICTION_INPUT['decision_participation']),
'组织公平感': data.get('organizational_justice', DEFAULT_PREDICTION_INPUT['organizational_justice']),
# JD-R 个人资源维度
'自我效能感': data.get('self_efficacy', DEFAULT_PREDICTION_INPUT['self_efficacy']),
'心理韧性': data.get('resilience', DEFAULT_PREDICTION_INPUT['resilience']),
'乐观程度': data.get('optimism', DEFAULT_PREDICTION_INPUT['optimism']),
# JD-R 中介变量
'工作倦怠': data.get('burnout', DEFAULT_PREDICTION_INPUT['burnout']),
'工作投入': data.get('work_engagement', DEFAULT_PREDICTION_INPUT['work_engagement']),
}
return pd.DataFrame([feature_row])