-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescriptive.py
63 lines (54 loc) · 1.48 KB
/
descriptive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
descriptive model: uses Multiple Correspondence Analysis on the dataset
"""
import pandas as pd
import prince
df = pd.read_csv("data/conditions.csv")
mca = prince.MCA(
n_components=2,
n_iter=3,
copy=True,
check_input=True,
engine='auto',
benzecri=True,
random_state=42
)
df_mca = mca.fit(df)
ax = df_mca.plot_coordinates(
X=df,
ax=None,
figsize=(13, 10),
show_row_points=False,
show_row_labels=False,
show_column_points=True,
show_column_labels=True,
legend_n_cols=1
).legend(loc='center left', bbox_to_anchor=(1, 0.5))
ax.get_figure().savefig('static/images/mca_plot.png')
# Tidying data
df = df.drop(columns=['Organ_transplant', 'Healthcare_worker', 'Pregnancy', 'Cachexia', 'Autoimm_disorder'])
df.columns = ['age', 'sex', 'smoking', 'alcohol', 'hypertension',
'diabetes', 'rheuma', 'dementia', 'cancer', 'copd',
'asthma', 'chd', 'ccd', 'cnd', 'cld',
'ckd', 'aids', 'death']
mca_clean = prince.MCA(
n_components=2,
n_iter=3,
copy=True,
check_input=True,
engine='auto',
benzecri=True,
random_state=42
)
df_mca_clean = mca_clean.fit(df)
ax_clean = df_mca_clean.plot_coordinates(
X=df,
ax=None,
figsize=(13, 10),
show_row_points=False,
show_row_labels=False,
show_column_points=True,
show_column_labels=True,
legend_n_cols=1
).legend(loc='center left', bbox_to_anchor=(1, 0.5))
ax_clean.get_figure().savefig('static/images/mca_plot_clean.png')