shap value :are the total positive shap sample values almost equal to the total negative shape sample values? [closed]

I write code to make analysis of the impact of TCGA data on the latent space.

Here is the code :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>test_input1 = tf.convert_to_tensor(tf.random.normal([X_train1.shape[0], n_input1]), dtype=tf.float32)
test_input2 = tf.convert_to_tensor(tf.random.normal([X_train2.shape[0], n_input2]), dtype=tf.float32)
input_tensor1 = tf.keras.Input(shape=(n_input1,))
input_tensor2 = tf.keras.Input(shape=(n_input2,))
combined_input = tf.concat([test_input1, test_input2], axis=1)
self_attention = SelfAttention(units=n_input1 + n_input2)
attention_output = self_attention(combined_input)
encoder = EncoderNetwork(n_input1, n_input2, n_hiddensh, activation=act, _init=func_init)
_ = encoder([test_input1,test_input2])
encoded_output = encoder([input_tensor1, input_tensor2])
wrapped_encoder = tf.keras.Model(inputs=[input_tensor1, input_tensor2], outputs=encoded_output)
load_encoder_weights(encoder, iterator)
load_attention_weights(self_attention, iterator)
self_attention_output = self_attention(combined_input)
test_input1_np = self_attention_output[0].numpy()
test_input2_np = self_attention_output[1].numpy()
explainer = shap.DeepExplainer(wrapped_encoder, [test_input1_np, test_input2_np])
shap_values = explainer.shap_values([test_input1_np, test_input2_np]
shap_values_0 = np.squeeze(shap_values[0])
feature_names_1 = [exp_feature_names[i - 1] for i in htseq_cmt[:, 2].astype(int)]
positive_counts_0 = np.sum(shap_values_0 > 0, axis=0)
negative_counts_0 = np.sum(shap_values_0 < 0, axis=0)
total_samples_0 = shap_values_0.shape[0]
positive_ratios_0 = positive_counts_0 / total_samples_0
negative_ratios_0 = negative_counts_0 / total_samples_0
positive_shap_sums_0 = np.sum(np.where(shap_values_0 > 0, shap_values_0, 0), axis=0)
negative_shap_sums_0 = np.sum(np.where(shap_values_0 < 0, shap_values_0, 0), axis=0)
</code>
<code>test_input1 = tf.convert_to_tensor(tf.random.normal([X_train1.shape[0], n_input1]), dtype=tf.float32) test_input2 = tf.convert_to_tensor(tf.random.normal([X_train2.shape[0], n_input2]), dtype=tf.float32) input_tensor1 = tf.keras.Input(shape=(n_input1,)) input_tensor2 = tf.keras.Input(shape=(n_input2,)) combined_input = tf.concat([test_input1, test_input2], axis=1) self_attention = SelfAttention(units=n_input1 + n_input2) attention_output = self_attention(combined_input) encoder = EncoderNetwork(n_input1, n_input2, n_hiddensh, activation=act, _init=func_init) _ = encoder([test_input1,test_input2]) encoded_output = encoder([input_tensor1, input_tensor2]) wrapped_encoder = tf.keras.Model(inputs=[input_tensor1, input_tensor2], outputs=encoded_output) load_encoder_weights(encoder, iterator) load_attention_weights(self_attention, iterator) self_attention_output = self_attention(combined_input) test_input1_np = self_attention_output[0].numpy() test_input2_np = self_attention_output[1].numpy() explainer = shap.DeepExplainer(wrapped_encoder, [test_input1_np, test_input2_np]) shap_values = explainer.shap_values([test_input1_np, test_input2_np] shap_values_0 = np.squeeze(shap_values[0]) feature_names_1 = [exp_feature_names[i - 1] for i in htseq_cmt[:, 2].astype(int)] positive_counts_0 = np.sum(shap_values_0 > 0, axis=0) negative_counts_0 = np.sum(shap_values_0 < 0, axis=0) total_samples_0 = shap_values_0.shape[0] positive_ratios_0 = positive_counts_0 / total_samples_0 negative_ratios_0 = negative_counts_0 / total_samples_0 positive_shap_sums_0 = np.sum(np.where(shap_values_0 > 0, shap_values_0, 0), axis=0) negative_shap_sums_0 = np.sum(np.where(shap_values_0 < 0, shap_values_0, 0), axis=0) </code>
test_input1 = tf.convert_to_tensor(tf.random.normal([X_train1.shape[0], n_input1]), dtype=tf.float32)
test_input2 = tf.convert_to_tensor(tf.random.normal([X_train2.shape[0], n_input2]), dtype=tf.float32)
input_tensor1 = tf.keras.Input(shape=(n_input1,))
input_tensor2 = tf.keras.Input(shape=(n_input2,))
combined_input = tf.concat([test_input1, test_input2], axis=1)
self_attention = SelfAttention(units=n_input1 + n_input2)
attention_output = self_attention(combined_input)
encoder = EncoderNetwork(n_input1, n_input2, n_hiddensh, activation=act, _init=func_init)
_ = encoder([test_input1,test_input2])
encoded_output = encoder([input_tensor1, input_tensor2])
wrapped_encoder = tf.keras.Model(inputs=[input_tensor1, input_tensor2], outputs=encoded_output)

load_encoder_weights(encoder, iterator)
load_attention_weights(self_attention, iterator)

self_attention_output = self_attention(combined_input)

test_input1_np = self_attention_output[0].numpy()
test_input2_np = self_attention_output[1].numpy()
explainer = shap.DeepExplainer(wrapped_encoder, [test_input1_np, test_input2_np])

shap_values = explainer.shap_values([test_input1_np, test_input2_np]
shap_values_0 = np.squeeze(shap_values[0]) 

feature_names_1 = [exp_feature_names[i - 1] for i in htseq_cmt[:, 2].astype(int)]  

positive_counts_0 = np.sum(shap_values_0 > 0, axis=0) 
negative_counts_0 = np.sum(shap_values_0 < 0, axis=0) 
total_samples_0 = shap_values_0.shape[0]  


positive_ratios_0 = positive_counts_0 / total_samples_0
negative_ratios_0 = negative_counts_0 / total_samples_0

positive_shap_sums_0 = np.sum(np.where(shap_values_0 > 0, shap_values_0, 0), axis=0)
negative_shap_sums_0 = np.sum(np.where(shap_values_0 < 0, shap_values_0, 0), axis=0)

The abnormal thing is the result of difference between the values of postive shap samples values and negative values is almost similar.

I don’t know if the weights and bias loading is incorrect.Or this data is special.

Is there any testing method to see if the abnormal result is related to data itself ?

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật