import warnings
def fxn():
warnings.warn("deprecated", DeprecationWarning)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fxn()
# importations de modules "local"
import sys
sys.path.append('functions/')
import base_notebook_light
import css_base_light
import fonctions_perso
import css_regression
import fonction_regression_lineaire
# import des librairies et des paramètres
from base_notebook_light import *
from css_base_light import *
from css_regression import *
# style pour les graphiques
plt.style.use('seaborn-notebook')
# repère de début de traitement pour calculer le temps tital d'exécution du notebook
start_time_m4 = time.time()
# import des données
dcf = pd.read_csv("data/exports/dc_anova.csv")
dcf.shape
(5750000, 11)
dcf = dcf[['code_pays', 'pays', 'pop', 'Gj', 'gdp', 'income_avg', 'y_child', 'pj', 'c_i_parent']]
dcf.columns = ['code_pays', 'pays', 'pop', 'gini', 'gdp', 'y_child_avg', 'y_child', 'elas', 'c_i_parent']
dcf.sample(2)
code_pays | pays | pop | gini | gdp | y_child_avg | y_child | elas | c_i_parent | |
---|---|---|---|---|---|---|---|---|---|
2157539 | HUN | Hongrie | 9991867.0 | 0.2741 | 18004.0 | 6101.341229 | 3279.2130 | 0.400000 | 5.0 |
1201982 | CZE | République Tchèque | 10425266.0 | 0.2529 | 23223.0 | 8235.293411 | 3067.3618 | 0.434041 | 80.0 |
dcf['ln_y_child'] = np.log(dcf['y_child'])
dcf['ln_y_child_avg'] = np.log(dcf['y_child_avg'])
dcf.sample(2)
code_pays | pays | pop | gini | gdp | y_child_avg | y_child | elas | c_i_parent | ln_y_child | ln_y_child_avg | |
---|---|---|---|---|---|---|---|---|---|---|---|
5244595 | TUR | Turquie | 70418604.0 | 0.4220 | 11904.0 | 6050.465331 | 11233.96100 | 0.5 | 40.0 | 9.326697 | 8.707890 |
2956745 | LAO | République Démocratique Populaire Lao | 6046620.0 | 0.3542 | 1960.0 | 1003.407353 | 450.35175 | 0.5 | 29.0 | 6.110029 | 6.911157 |
dcf['pop'] = dcf['pop'].apply(lambda x: int(x))
dcf['pop'] = dcf['pop'].apply(lambda x: "{:,}".format(x).replace(",", " "))
dcf['gdp'] = dcf['gdp'].apply(lambda x: round(x,2))
dcf['y_child'] = dcf['y_child'].apply(lambda x: round(x,2))
dcf['y_child_avg'] = dcf['y_child_avg'].apply(lambda x: round(x,2))
dcf['elas'] = dcf['elas'].apply(lambda x: round(x,2))
dcf['c_i_parent'] = dcf['c_i_parent'].apply(lambda x: int(x))
dcf.sample(2)
code_pays | pays | pop | gini | gdp | y_child_avg | y_child | elas | c_i_parent | ln_y_child | ln_y_child_avg | |
---|---|---|---|---|---|---|---|---|---|---|---|
2353237 | IRN | République Islamique d'Iran | 72 120 604 | 0.4344 | 10446.0 | 5832.66 | 1240.29 | 0.66 | 19 | 7.123098 | 8.671228 |
1808996 | GEO | Géorgie | 4 142 655 | 0.3901 | 4516.0 | 1363.76 | 537.60 | 0.50 | 96 | 6.287116 | 7.218000 |
code_pays
: code international iso-3pays
: nom du pays en françaispop
: nombre d'habitants du paysgini
: indice de gini du paysgdp
: PIB/hab en $PPAy_child_avg
: revenu moyen des enfantsy_child
: revenu enfant par centile c_i_parentelas
: coef d'élasticité du paysc_i_parent
: centile de revenu parentln_y_child
: logarithme de y_childln_y_child_avg
: logarithme de y_child_avgc_i_parent
=> les mêmes observations sont donc dupliquées 500 fois # version allégée pour les graphs
dcf_graph = dcf.drop(columns=["c_i_parent"]).drop_duplicates()
dcf_graph.shape
(11500, 10)
Représentation graphique pour les 6 pays retenus lors de la mission 2 :
Slovénie, Honduras, Géorgie, États-Unis, Ukraine, Paraguay
pays_selected = ['Slovénie', 'Honduras', 'Géorgie', 'États-Unis', 'Ukraine', 'Paraguay']
pays_sel_l = []
for pays in pays_selected:
pays_sel_l.append(dcf[dcf['pays'] == pays])
dcf_sel = pd.concat(pays_sel_l)
dcf_sel.shape
dcf_sel.sample(4)
(300000, 11)
code_pays | pays | pop | gini | gdp | y_child_avg | y_child | elas | c_i_parent | ln_y_child | ln_y_child_avg | |
---|---|---|---|---|---|---|---|---|---|---|---|
2098933 | HND | Honduras | 7 980 955 | 0.6017 | 3628.0 | 3296.27 | 15031.88 | 0.66 | 98 | 9.617929 | 8.100546 |
1842366 | GEO | Géorgie | 4 142 655 | 0.3901 | 4516.0 | 1363.76 | 2160.37 | 0.50 | 85 | 7.678035 | 7.218000 |
5394913 | UKR | Ukraine | 46 158 711 | 0.2551 | 6721.0 | 3349.39 | 5321.15 | 0.40 | 92 | 8.579444 | 8.116533 |
1819655 | GEO | Géorgie | 4 142 655 | 0.3901 | 4516.0 | 1363.76 | 889.74 | 0.50 | 29 | 6.790935 | 7.218000 |
sns.set()
sns.set_theme(context='notebook', style='whitegrid', palette='Set2', font_scale=1)
plt.figure(figsize=(8,5))
sns.boxplot(x="pays", y="y_child", data=dcf_sel, flierprops=dict(marker='o', markersize=3))
plt.xlabel("", size=0)
plt.ylabel("Revenu (en $PPA)", size=12)
plt.title("Répartition des revenus dans les pays sélectionnés (mission 2)", fontsize=14, color="darkred")
plt.grid(True, linestyle='--', alpha=0.3)
plt.tight_layout()
plt.savefig('data/exports/img_charts/12.boxplot_sns_revenus_pays_selected.png', dpi = 200)
plt.show();
import plotly.graph_objects as go
def plot_box_plot(pays_l, var_x, num_graph=None):
x_data = pays_l
y_data=[]
for pays in pays_l:
y_data.append(dcf_graph.loc[dcf_graph['pays'] == pays, var_x])
colors = ['rgba(93, 164, 214, 0.5)', 'rgba(255, 144, 14, 0.5)', 'rgba(44, 160, 101, 0.5)',
'rgba(255, 65, 54, 0.5)', 'rgba(207, 114, 255, 0.5)', 'rgba(127, 96, 0, 0.5)']
fig = go.Figure()
for xd, yd, cls in zip(x_data, y_data, colors):
fig.add_trace(go.Box(
y=yd,
name=xd,
boxpoints='all',
jitter=0.5,
whiskerwidth=0.2,
fillcolor=cls,
marker_size=2,
line_width=1)
)
fig.update_layout(
title='Répartition des revenus',
yaxis=dict(
autorange=True,
showgrid=True,
zeroline=True,
gridcolor='rgb(255, 255, 255)',
gridwidth=1,
zerolinecolor='rgb(255, 255, 255)',
zerolinewidth=2,
),
margin=dict(
l=40,
r=30,
b=80,
t=100,
),
paper_bgcolor='rgb(243, 243, 243)',
plot_bgcolor='rgb(243, 243, 243)',
showlegend=False
)
fig.write_html("data/exports/img_charts/"+(str(num_graph) if num_graph is not None else "")+"boxplot_plot_revenus_pays_selected.html")
fig.write_image("data/exports/img_charts/"+str((num_graph) if num_graph is not None else "")+"boxplot_plot_revenus_pays_selected.png")
fig.show();
plot_box_plot(pays_selected, 'y_child', num_graph=13)