ai-code-detection / xai /grouping.py
joshnavip's picture
Initial commit: AI code detection project (without binary files)
b144cb7
raw
history blame contribute delete
514 Bytes
def map_feature_group(idx):
if idx < 8:
return "Statistical"
elif idx < 8 + 5:
return "AST"
elif idx < 8 + 5 + 11:
return "Stylometry"
elif idx < 8 + 5 + 11 + 2:
return "Language"
else:
return "Semantic"
def group_shap_explanations(shap_result):
grouped = {}
for item in shap_result:
group = map_feature_group(item["feature_index"])
grouped.setdefault(group, 0)
grouped[group] += abs(item["impact"])
return grouped