近年来,随着XAI的兴起,使得AI是可解释的、可信任的、可优化的,目前将新技术XAI运用于冰机、空压机等设备的PHM的案例较少,对于实时数据监测的PHM,采用XAI进行异常解释可得到不错的效果,本文使用无监督学习中的自编码技术对时序数据进行异常侦测,采用可解释器shap进行异常原因定位
explainer = shap.DeepExplainer(model=model, data=torch.from_numpy(X[:200].astype(np.float32)))#得到shap基线 shap_value_single = explainer.shap_values(X=torch.from_numpy(XpredictInputData.astype(np.float32))) shap_values_weight_mean = np.zeros(260) name_features = anamoly_data.columns#特征名称 for j in range(len(hh)): input_label_index_value = hh[j] shap_values = np.array([], dtype=np.float64) weight_value = weight_values[j] features=[] values=[] for i in range(0, LOOKBACK_SIZE): tmp_shap = shap_value_single[input_label_index_value][0][i] shap_values = np.append(shap_values, tmp_shap) features.extend([s + '_tt' + str(3 * (LOOKBACK_SIZE - i)) for s in name_features]) values.extend(anamoly_data.iloc[specific_prediction_sample_to_explain_index-(LOOKBACK_SIZE-i-1),:]) shap_values_weight_mean += weight_value * shap_values