chot ket qua 08_07

This commit is contained in:
Victor Phan
2026-07-08 15:16:19 +07:00
parent b22d327c5f
commit 1720207f82
4 changed files with 40 additions and 4 deletions
@@ -0,0 +1,4 @@
Cluster,0,1,0_Pct,1_Pct
1,27,20,57.446808510638306,42.5531914893617
2,32,29,52.459016393442624,47.540983606557376
3,44,155,22.110552763819097,77.88944723618091
1 Cluster 0 1 0_Pct 1_Pct
2 1 27 20 57.446808510638306 42.5531914893617
3 2 32 29 52.459016393442624 47.540983606557376
4 3 44 155 22.110552763819097 77.88944723618091
@@ -0,0 +1,4 @@
Cluster,0,1,0_Pct,1_Pct
1,10,37,21.27659574468085,78.72340425531915
2,22,39,36.0655737704918,63.934426229508205
3,4,195,2.0100502512562812,97.98994974874373
1 Cluster 0 1 0_Pct 1_Pct
2 1 10 37 21.27659574468085 78.72340425531915
3 2 22 39 36.0655737704918 63.934426229508205
4 3 4 195 2.0100502512562812 97.98994974874373
@@ -0,0 +1,27 @@
import sys
sys.stdout.reconfigure(encoding='utf-8')
import pandas as pd
import scipy.stats as stats
import os
base_dir = r'c:\Users\NASPC\Documents\Du án tại SG tháng 8\Project_Code_and_Results'
df = pd.read_excel(r'c:\Users\NASPC\Documents\Du án tại SG tháng 8\Data_VN_filter_v5_with_clusters.xlsx')
results = []
for var in ['Donation', 'Decision']:
df_clean = df.dropna(subset=['Cluster', var])
ct = pd.crosstab(df_clean['Cluster'], df_clean[var])
chi2, p, dof, _ = stats.chi2_contingency(ct)
ct_pct = ct.div(ct.sum(axis=1), axis=0) * 100
print(f"\n--- {var} ---")
print("Counts:")
print(ct)
print("\nPercentages:")
print(ct_pct)
print(f"Chi-square: {chi2:.4f}, p-value: {p:.4f}")
res = pd.concat([ct, ct_pct.add_suffix('_Pct')], axis=1)
res.to_csv(os.path.join(base_dir, '3_PCA_and_HCA', f'Profiling_H4_{var}_Contingency.csv'))
print("\nĐã xuất kết quả kiểm định H4.")