application_vnd.jupyter.stderr_output_2.png text_html_output_4.png application_vnd.jupyter.stderr_output_4.png text_html_output_2.png image_output_5.png image_output_7.png image_output_4.png application_vnd.jupyter.stderr_output_3.png application_vnd.jupyter.stderr_output_5.png text_html_output_1.png image_output_6.png application_vnd.jupyter.stderr_output_1.png image_output_3.png image_output_2.png image_output_1.png text_html_output_3.png
from IPython.core.display import HTML

from IPython.display import Markdown

from scipy.stats import norm, skew, kurtosis

import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import scipy.stats as stats

import seaborn as sns

"""Personnalisation de la visualisation"""
plt.style.use('bmh')
sns.set_style({'axes.grid': False})
'On peut utiliser le gras , souligné etc avec markedown'
from IPython.display import Markdown
def bold(string):
    pass
pd.options.display.max_rows = 150

df1 = pd.read_csv('../input/projet-data-mining/test.csv')
df2 = pd.read_csv('../input/projet-data-mining/train.csv')
data = pd.concat([df1, df2], axis=0, ignore_index=True)

data.shape

"""Type des données de nos variables."""
bold('**Type des données de nos variables:**')
listeInt = ''
listeFloat = ''
listeObj = ''
for col in data.columns:
    if data[col].dtype in ['float64']:
        listeFloat += col + ','
    if data[col].dtype in ['int64']:
        listeInt += col + ','
    if data[col].dtype in ['object']:
        listeObj += col + ','

data1 = data.iloc[:, 2:]

categorical_indexes = [0, 1, 3, 4] + list(range(6, 20))
data1.iloc[:, categorical_indexes] = data1.iloc[:, categorical_indexes].astype('category')

def graph_unitaire(data1,nom_colonne,proba):
    f, (ax1, ax2) = plt.subplots(1,2,figsize=(20,8))
    sns.kdeplot(data1[nom_colonne],ax = ax1,color ='blue',shade=True,
                label=("Skewness : %.2f"%(data1[nom_colonne].skew()),
                       "Kurtosis: %.2f"%(data1[nom_colonne].kurtosis())))
    ax1.set_xlabel(nom_colonne,color='black',fontsize=12)
    ax1.set_title(nom_colonne + ' Kdeplot',fontsize=14)
    ax1.axvline(data1[nom_colonne].mean() , color ='g',linestyle = '--')
    ax1.legend(loc ='upper right',fontsize=12,ncol=2)
    
    sns.distplot(data1[nom_colonne] , fit=norm,ax = ax2);
    ax2.set_xlabel(nom_colonne,color='black',fontsize=12)
    ax2.set_title(nom_colonne + ' distribution',fontsize=14)
    ax2.axvline(data1[nom_colonne].mean() , color ='g',linestyle = '--')  
    (mu, sigma) = norm.fit(data1[nom_colonne])
    ax2.legend(['Normal dist. ($\mu=$ {:.2f} et $\sigma=$ {:.2f} )'.format(mu, sigma)],loc ='upper right',fontsize=12,ncol=2)
    
    sns.despine()
    plt.show()
    
    if proba==True:
        graph_duo(data1,nom_colonne)
        
    return(data1[nom_colonne].skew(),data1[nom_colonne].kurtosis())

def graph_duo(data1,nom_colonne):
    
    #Get also the QQ-plot
    fig = plt.figure()
    res = stats.probplot(data1[nom_colonne], plot=plt)
    plt.show()

""" On parcours les différentes colonnes """
for col in data1.columns:
    ' Uniquement les colonnes numériques '
    if data1[col].dtype in ['int64', 'float64']:
        display(HTML('<strong>Analyse de la variable ' + col + '</strong>'))
        skew1, kurto1 = graph_unitaire(data1, col, True)