Giter Club home page Giter Club logo

desafiolatam-ejercicios-2's Introduction

alttext

Unidad 4: Hipótesis y correlación - Sesión 1

Ejercicio 1: Preparación del ambiente de trabajo

  • Importe las librerías básicas para el análisis de datos

  • Descarge e importe el archivo nations.csv. warning: va a encontrar un error en el formato ¿Cómo lo podemos solucionar?.

  • La base de datos contiene información a nivel mundial sobre demografía:

    • country: País.
    • region: Continente del país.
    • gdp: Producto Interno Bruto per cápita, precios 2005.
    • school: Promedio años de escolaridad.
    • adfert: Fertilidad adolescente (Nacimientos 1:1000 en mujeres entre 15 y 19).
    • chldmort: Probabilidad de muerte antes de los 5 años por cada 1000.
    • life: Esperanza de vida al nacer.
    • pop: Población total.
    • urban: Porcentaje de población urbana.
    • femlab: Tasa entre hombres y mujeres en el mercado laboral.
    • literacy: Tasa de alfabetismo.
    • co2: Toneladas de Co2 mitidas per cápita.
    • gini: Coeficiente de desigualdad del ingreso.
  • Apellidos desde la A hasta la N: Enfocarse en las variables chldmort, adfert y life.

  • Apellidos desde la M hasta la Z: Enfocarse en las variables femlab, literacy y school.

Ejercicio 2:A continuación se presenta una serie de gráficos construídos con matplotlib. Se le pide refactorizarlos utilizando seaborn.

  • Se presenta la función que se utilizó para construírlos. Intente llegar al resultado con mayor similitud. Comente los principales resultados de los gráficos.
def binarize_histogram(dataframe, variable):
    tmp = dataframe
    tmp['binarize'] = np.where(tmp[variable] > np.mean(tmp[variable]), 1, 0)
    
    hist_1 = tmp[tmp['binarize'] == 1][variable].dropna()
    hist_0 = tmp[tmp['binarize'] == 0][variable].dropna()
    
    plt.subplot(1, 2, 1)
    plt.hist(hist_0, alpha=.6, color='lightgrey')
    plt.axvline(np.mean(hist_0))
    plt.title("{0} <= {1}".format(variable, round(np.mean(hist_0), 3)))
    plt.subplot(1, 2, 2)
    plt.hist(hist_1, alpha=.6, color='lightgrey')
    plt.axvline(np.mean(hist_1))
    plt.title("{0} >= {1}".format(variable, round(np.mean(hist_0), 3)))

binarize_histogram(df, 'adfert')

png

def grouped_boxplot(dataframe, variable, group_by):
    tmp = dataframe
    stratify_by = tmp[group_by].unique()
    
    if len(stratify_by) / 2 > 3:
        fig, ax = plt.subplots(2, len(stratify_by),sharey=True)
    else:
        fig, ax = plt.subplots(1, len(stratify_by),sharey=True)
        
    for i, n in enumerate(stratify_by):
        ax[i].boxplot(tmp[tmp[group_by] == n][variable])
        ax[i].set_title(n)
        
grouped_boxplot(df, 'adfert', 'region')

png

def grouped_scatterplot(dataframe, x, y, group_by):
    tmp = dataframe
    stratify_by = tmp[group_by].unique()
    
    if len(stratify_by) / 2 > 3:
        fig, ax = plt.subplots(2, len(stratify_by),sharey=True)
    else:
        fig, ax = plt.subplots(1, len(stratify_by),sharey=True)
        
    for i, n in enumerate(stratify_by):
        tmp_group_plt = tmp[tmp[group_by] == n]
        ax[i].plot(tmp_group_plt[x], tmp_group_plt[y], 'o')
        ax[i].set_title(n)

grouped_scatterplot(df, 'school', 'adfert', 'region')

png

Ejercicio 3: Genere un heatmap entre todas las variables.

  • En base a las variables de interés asignadas, comente cuáles son las principales correlaciones existentes, tomando como criterio de corte aquellas superior a .6

Ejercicio 4: En base a las principales correlaciones, sepárelas en un nuevo objeto y calcule la matriz de correlaciones para todas las regiones

  • tip: Genere una nueva tabla segmentando con la siguiente sintáxis: tmp = df.loc[:,['variables', 'a', 'agregar']]. No olvide agregar la variable region.
  • tip: Genere un loop para recorrer cada región y generar un heatmap.
  • Comente brevemente las principales correlaciones a través de las regiones.

desafiolatam-ejercicios-2's People

Contributors

claudio-oj avatar

desafiolatam-ejercicios-2's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.