You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.2 KiB
Python

import pandas as pd
# 读取特征
features = pd.read_excel('feature.xlsx')
# 计算权重数字化值
features['权重数字化值'] = features['强迫症状数字化'] * 0.135 + features['人际关系敏感数字化'] * 0.085 + features['抑郁数字化'] * 0.08 + features['多因子症状'] * 0.2 + features['母亲教养方式数字化'] * 0.09 + features['父亲教养方式数字化'] * 0.09 + features['自评家庭经济条件数字化'] * 0.06 + features['有无心理治疗(咨询)史数字化'] * 0.06 + features['学业情况数字化'] * 0.08 + features['出勤情况数字化'] * 0.12
# 定义SCL-90的10个因子
scl_90_factors = ["躯体化", "强迫症状", "人际关系敏感", "抑郁", "焦虑", "敌对", "恐怖", "偏执", "精神病性", "其他"]
# 计算预警等级
def calculate_warning_level(row):
factors = row[scl_90_factors]
if (factors >= 4).sum() >= 1 or (factors >= 3).sum() >= 8:
return 1
elif (factors >= 3).sum() >= 1:
return 2
elif (factors >= 2).sum() >= 1:
return 3
else:
return 4
features['label'] = features.apply(calculate_warning_level, axis=1)
# 保存带有预警等级的数据
features.to_excel('feature_label.xlsx', index=False)