{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e4f267ab",
   "metadata": {},
   "source": [
    "# Laboratory Session 1: Machine Learning Landscape\n",
    "\n",
    "## Introducción\n",
    "\n",
    "Para la presente sesión (Machine Learning Landscape) el alumno explorará el uso del entorno Jupyter para el análisis de datos y programación enfocada a la ciencia de datos. \n",
    "\n",
    "En esta sesión aprenderá los conceptos básicos de los módulos `Numpy`, `Pandas`, `Matplotlib` y `Sklearn` a través del desarrollo de **un modelo lineal para determinar el nivel de satisfacción de vida a partir del parámetro GDP**. En consecuencia, el modelo desarrollado utiliza como datos de entrenamiento información recolectada por la OECD y GDP. Los parámetros obtenidos después del entrenamiento son usados para evaluar por inspección visual el comportamiento de los datos contra los datos reales. Por lo tanto, para la presente sección se pueden identificar los siguientes objetivos.\n",
    "\n",
    "Objetivo General: *Desarrollar un modelo basado en la regresión lineal usando las funciones `fit` del módulo Sklearn para determinar el nivel de satisfacción de vida en función de GDP de cada país.*\n",
    "\n",
    "Objetivos Específicos:\n",
    "\n",
    "- Aprender el manejo básico de la plataforma Jupyter y los comandos de inserción, copia, borrado y evaluación de celdas\n",
    "- Conocer el procedimiento de lectura de archivos CSV\n",
    "- Relacionarse con el procedimiento de acceso a datos por nombres de columnas, manipulación, edición y filtrado de datos con la estructura de Pandas\n",
    "- Crear una función en Python para leer las bases de datos de la OECD y GDP, y posteriormente crear un conjunto de datos que exclusivamente incluyan \"Life Satisfaction\" y  \"GDP per capita\"\n",
    "- Entrenar un modelo basado en la regresión lineal \n",
    "- Comparar el modelo con los datos reales y determinar nuevos valores de instancias"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "53912466",
   "metadata": {},
   "source": [
    "# The Data: Life Satisfaction and GDP per capita\n",
    "The next sections will explorer the two datasets: 1) Organisation for Economic Co-operation and Development and 2)International Monetary Fund.\n",
    "\n",
    "## Life satisfaction data description\n",
    "\n",
    "This dataset was obtained from the OECD's website at: http://stats.oecd.org/index.aspx?DataSetCode=BLI\n",
    "\n",
    "```\n",
    "Int64Index: 3292 entries, 0 to 3291\n",
    "Data columns (total 17 columns):\n",
    "﻿\"LOCATION\"              3292 non-null object\n",
    "Country                  3292 non-null object\n",
    "INDICATOR                3292 non-null object\n",
    "Indicator                3292 non-null object\n",
    "MEASURE                  3292 non-null object\n",
    "Measure                  3292 non-null object\n",
    "INEQUALITY               3292 non-null object\n",
    "Inequality               3292 non-null object\n",
    "Unit Code                3292 non-null object\n",
    "Unit                     3292 non-null object\n",
    "PowerCode Code           3292 non-null int64\n",
    "PowerCode                3292 non-null object\n",
    "Reference Period Code    0 non-null float64\n",
    "Reference Period         0 non-null float64\n",
    "Value                    3292 non-null float64\n",
    "Flag Codes               1120 non-null object\n",
    "Flags                    1120 non-null object\n",
    "dtypes: float64(3), int64(1), object(13)\n",
    "memory usage: 462.9+ KB\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "72915229",
   "metadata": {},
   "source": [
    "### Example using Python Pandas\n",
    "\n",
    "```\n",
    ">>> life_sat = pd.read_csv(\"oecd_bli_2015.csv\", thousands=',')\n",
    "\n",
    ">>> life_sat_total = life_sat[life_sat[\"INEQUALITY\"]==\"TOT\"]\n",
    "\n",
    ">>> life_sat_total = life_sat_total.pivot(index=\"Country\", columns=\"Indicator\", values=\"Value\")\n",
    "\n",
    ">>> life_sat_total.info()\n",
    "<class 'pandas.core.frame.DataFrame'>\n",
    "Index: 37 entries, Australia to United States\n",
    "Data columns (total 24 columns):\n",
    "Air pollution                                37 non-null float64\n",
    "Assault rate                                 37 non-null float64\n",
    "Consultation on rule-making                  37 non-null float64\n",
    "Dwellings without basic facilities           37 non-null float64\n",
    "Educational attainment                       37 non-null float64\n",
    "Employees working very long hours            37 non-null float64\n",
    "Employment rate                              37 non-null float64\n",
    "Homicide rate                                37 non-null float64\n",
    "Household net adjusted disposable income     37 non-null float64\n",
    "Household net financial wealth               37 non-null float64\n",
    "Housing expenditure                          37 non-null float64\n",
    "Job security                                 37 non-null float64\n",
    "Life expectancy                              37 non-null float64\n",
    "Life satisfaction                            37 non-null float64\n",
    "Long-term unemployment rate                  37 non-null float64\n",
    "Personal earnings                            37 non-null float64\n",
    "Quality of support network                   37 non-null float64\n",
    "Rooms per person                             37 non-null float64\n",
    "Self-reported health                         37 non-null float64\n",
    "Student skills                               37 non-null float64\n",
    "Time devoted to leisure and personal care    37 non-null float64\n",
    "Voter turnout                                37 non-null float64\n",
    "Water quality                                37 non-null float64\n",
    "Years in education                           37 non-null float64\n",
    "dtypes: float64(24)\n",
    "memory usage: 7.2+ KB\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "86e530da",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 3292 entries, 0 to 3291\n",
      "Data columns (total 17 columns):\n",
      " #   Column                 Non-Null Count  Dtype  \n",
      "---  ------                 --------------  -----  \n",
      " 0   LOCATION               3292 non-null   object \n",
      " 1   Country                3292 non-null   object \n",
      " 2   INDICATOR              3292 non-null   object \n",
      " 3   Indicator              3292 non-null   object \n",
      " 4   MEASURE                3292 non-null   object \n",
      " 5   Measure                3292 non-null   object \n",
      " 6   INEQUALITY             3292 non-null   object \n",
      " 7   Inequality             3292 non-null   object \n",
      " 8   Unit Code              3292 non-null   object \n",
      " 9   Unit                   3292 non-null   object \n",
      " 10  PowerCode Code         3292 non-null   int64  \n",
      " 11  PowerCode              3292 non-null   object \n",
      " 12  Reference Period Code  0 non-null      float64\n",
      " 13  Reference Period       0 non-null      float64\n",
      " 14  Value                  3292 non-null   float64\n",
      " 15  Flag Codes             1120 non-null   object \n",
      " 16  Flags                  1120 non-null   object \n",
      "dtypes: float64(3), int64(1), object(13)\n",
      "memory usage: 437.3+ KB\n"
     ]
    }
   ],
   "source": [
    "# Load the data\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "url = \"https://raw.githubusercontent.com/machine-learning-course-uac/1-ml-landscape/main/oecd_bli_2015.csv\"\n",
    "oecd_bli = pd.read_csv(url, thousands=',')\n",
    "oecd_bli.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7a58ef40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>LOCATION</th>\n",
       "      <th>Country</th>\n",
       "      <th>INDICATOR</th>\n",
       "      <th>Indicator</th>\n",
       "      <th>MEASURE</th>\n",
       "      <th>Measure</th>\n",
       "      <th>INEQUALITY</th>\n",
       "      <th>Inequality</th>\n",
       "      <th>Unit Code</th>\n",
       "      <th>Unit</th>\n",
       "      <th>PowerCode Code</th>\n",
       "      <th>PowerCode</th>\n",
       "      <th>Reference Period Code</th>\n",
       "      <th>Reference Period</th>\n",
       "      <th>Value</th>\n",
       "      <th>Flag Codes</th>\n",
       "      <th>Flags</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AUS</td>\n",
       "      <td>Australia</td>\n",
       "      <td>HO_BASE</td>\n",
       "      <td>Dwellings without basic facilities</td>\n",
       "      <td>L</td>\n",
       "      <td>Value</td>\n",
       "      <td>TOT</td>\n",
       "      <td>Total</td>\n",
       "      <td>PC</td>\n",
       "      <td>Percentage</td>\n",
       "      <td>0</td>\n",
       "      <td>units</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.10</td>\n",
       "      <td>E</td>\n",
       "      <td>Estimated value</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AUT</td>\n",
       "      <td>Austria</td>\n",
       "      <td>HO_BASE</td>\n",
       "      <td>Dwellings without basic facilities</td>\n",
       "      <td>L</td>\n",
       "      <td>Value</td>\n",
       "      <td>TOT</td>\n",
       "      <td>Total</td>\n",
       "      <td>PC</td>\n",
       "      <td>Percentage</td>\n",
       "      <td>0</td>\n",
       "      <td>units</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>BEL</td>\n",
       "      <td>Belgium</td>\n",
       "      <td>HO_BASE</td>\n",
       "      <td>Dwellings without basic facilities</td>\n",
       "      <td>L</td>\n",
       "      <td>Value</td>\n",
       "      <td>TOT</td>\n",
       "      <td>Total</td>\n",
       "      <td>PC</td>\n",
       "      <td>Percentage</td>\n",
       "      <td>0</td>\n",
       "      <td>units</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>CAN</td>\n",
       "      <td>Canada</td>\n",
       "      <td>HO_BASE</td>\n",
       "      <td>Dwellings without basic facilities</td>\n",
       "      <td>L</td>\n",
       "      <td>Value</td>\n",
       "      <td>TOT</td>\n",
       "      <td>Total</td>\n",
       "      <td>PC</td>\n",
       "      <td>Percentage</td>\n",
       "      <td>0</td>\n",
       "      <td>units</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.20</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>CZE</td>\n",
       "      <td>Czech Republic</td>\n",
       "      <td>HO_BASE</td>\n",
       "      <td>Dwellings without basic facilities</td>\n",
       "      <td>L</td>\n",
       "      <td>Value</td>\n",
       "      <td>TOT</td>\n",
       "      <td>Total</td>\n",
       "      <td>PC</td>\n",
       "      <td>Percentage</td>\n",
       "      <td>0</td>\n",
       "      <td>units</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.90</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3287</th>\n",
       "      <td>EST</td>\n",
       "      <td>Estonia</td>\n",
       "      <td>WL_TNOW</td>\n",
       "      <td>Time devoted to leisure and personal care</td>\n",
       "      <td>L</td>\n",
       "      <td>Value</td>\n",
       "      <td>WMN</td>\n",
       "      <td>Women</td>\n",
       "      <td>HOUR</td>\n",
       "      <td>Hours</td>\n",
       "      <td>0</td>\n",
       "      <td>units</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>14.43</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3288</th>\n",
       "      <td>ISR</td>\n",
       "      <td>Israel</td>\n",
       "      <td>WL_TNOW</td>\n",
       "      <td>Time devoted to leisure and personal care</td>\n",
       "      <td>L</td>\n",
       "      <td>Value</td>\n",
       "      <td>WMN</td>\n",
       "      <td>Women</td>\n",
       "      <td>HOUR</td>\n",
       "      <td>Hours</td>\n",
       "      <td>0</td>\n",
       "      <td>units</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>14.24</td>\n",
       "      <td>E</td>\n",
       "      <td>Estimated value</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3289</th>\n",
       "      <td>RUS</td>\n",
       "      <td>Russia</td>\n",
       "      <td>WL_TNOW</td>\n",
       "      <td>Time devoted to leisure and personal care</td>\n",
       "      <td>L</td>\n",
       "      <td>Value</td>\n",
       "      <td>WMN</td>\n",
       "      <td>Women</td>\n",
       "      <td>HOUR</td>\n",
       "      <td>Hours</td>\n",
       "      <td>0</td>\n",
       "      <td>units</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>14.75</td>\n",
       "      <td>E</td>\n",
       "      <td>Estimated value</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3290</th>\n",
       "      <td>SVN</td>\n",
       "      <td>Slovenia</td>\n",
       "      <td>WL_TNOW</td>\n",
       "      <td>Time devoted to leisure and personal care</td>\n",
       "      <td>L</td>\n",
       "      <td>Value</td>\n",
       "      <td>WMN</td>\n",
       "      <td>Women</td>\n",
       "      <td>HOUR</td>\n",
       "      <td>Hours</td>\n",
       "      <td>0</td>\n",
       "      <td>units</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>14.12</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3291</th>\n",
       "      <td>OECD</td>\n",
       "      <td>OECD - Total</td>\n",
       "      <td>WL_TNOW</td>\n",
       "      <td>Time devoted to leisure and personal care</td>\n",
       "      <td>L</td>\n",
       "      <td>Value</td>\n",
       "      <td>WMN</td>\n",
       "      <td>Women</td>\n",
       "      <td>HOUR</td>\n",
       "      <td>Hours</td>\n",
       "      <td>0</td>\n",
       "      <td>units</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>14.74</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3292 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     LOCATION         Country INDICATOR  \\\n",
       "0         AUS       Australia   HO_BASE   \n",
       "1         AUT         Austria   HO_BASE   \n",
       "2         BEL         Belgium   HO_BASE   \n",
       "3         CAN          Canada   HO_BASE   \n",
       "4         CZE  Czech Republic   HO_BASE   \n",
       "...       ...             ...       ...   \n",
       "3287      EST         Estonia   WL_TNOW   \n",
       "3288      ISR          Israel   WL_TNOW   \n",
       "3289      RUS          Russia   WL_TNOW   \n",
       "3290      SVN        Slovenia   WL_TNOW   \n",
       "3291     OECD    OECD - Total   WL_TNOW   \n",
       "\n",
       "                                      Indicator MEASURE Measure INEQUALITY  \\\n",
       "0            Dwellings without basic facilities       L   Value        TOT   \n",
       "1            Dwellings without basic facilities       L   Value        TOT   \n",
       "2            Dwellings without basic facilities       L   Value        TOT   \n",
       "3            Dwellings without basic facilities       L   Value        TOT   \n",
       "4            Dwellings without basic facilities       L   Value        TOT   \n",
       "...                                         ...     ...     ...        ...   \n",
       "3287  Time devoted to leisure and personal care       L   Value        WMN   \n",
       "3288  Time devoted to leisure and personal care       L   Value        WMN   \n",
       "3289  Time devoted to leisure and personal care       L   Value        WMN   \n",
       "3290  Time devoted to leisure and personal care       L   Value        WMN   \n",
       "3291  Time devoted to leisure and personal care       L   Value        WMN   \n",
       "\n",
       "     Inequality Unit Code        Unit  PowerCode Code PowerCode  \\\n",
       "0         Total        PC  Percentage               0     units   \n",
       "1         Total        PC  Percentage               0     units   \n",
       "2         Total        PC  Percentage               0     units   \n",
       "3         Total        PC  Percentage               0     units   \n",
       "4         Total        PC  Percentage               0     units   \n",
       "...         ...       ...         ...             ...       ...   \n",
       "3287      Women      HOUR       Hours               0     units   \n",
       "3288      Women      HOUR       Hours               0     units   \n",
       "3289      Women      HOUR       Hours               0     units   \n",
       "3290      Women      HOUR       Hours               0     units   \n",
       "3291      Women      HOUR       Hours               0     units   \n",
       "\n",
       "      Reference Period Code  Reference Period  Value Flag Codes  \\\n",
       "0                       NaN               NaN   1.10          E   \n",
       "1                       NaN               NaN   1.00        NaN   \n",
       "2                       NaN               NaN   2.00        NaN   \n",
       "3                       NaN               NaN   0.20        NaN   \n",
       "4                       NaN               NaN   0.90        NaN   \n",
       "...                     ...               ...    ...        ...   \n",
       "3287                    NaN               NaN  14.43        NaN   \n",
       "3288                    NaN               NaN  14.24          E   \n",
       "3289                    NaN               NaN  14.75          E   \n",
       "3290                    NaN               NaN  14.12        NaN   \n",
       "3291                    NaN               NaN  14.74        NaN   \n",
       "\n",
       "                Flags  \n",
       "0     Estimated value  \n",
       "1                 NaN  \n",
       "2                 NaN  \n",
       "3                 NaN  \n",
       "4                 NaN  \n",
       "...               ...  \n",
       "3287              NaN  \n",
       "3288  Estimated value  \n",
       "3289  Estimated value  \n",
       "3290              NaN  \n",
       "3291              NaN  \n",
       "\n",
       "[3292 rows x 17 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "oecd_bli"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d1c803f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 888 entries, 0 to 3217\n",
      "Data columns (total 17 columns):\n",
      " #   Column                 Non-Null Count  Dtype  \n",
      "---  ------                 --------------  -----  \n",
      " 0   LOCATION               888 non-null    object \n",
      " 1   Country                888 non-null    object \n",
      " 2   INDICATOR              888 non-null    object \n",
      " 3   Indicator              888 non-null    object \n",
      " 4   MEASURE                888 non-null    object \n",
      " 5   Measure                888 non-null    object \n",
      " 6   INEQUALITY             888 non-null    object \n",
      " 7   Inequality             888 non-null    object \n",
      " 8   Unit Code              888 non-null    object \n",
      " 9   Unit                   888 non-null    object \n",
      " 10  PowerCode Code         888 non-null    int64  \n",
      " 11  PowerCode              888 non-null    object \n",
      " 12  Reference Period Code  0 non-null      float64\n",
      " 13  Reference Period       0 non-null      float64\n",
      " 14  Value                  888 non-null    float64\n",
      " 15  Flag Codes             58 non-null     object \n",
      " 16  Flags                  58 non-null     object \n",
      "dtypes: float64(3), int64(1), object(13)\n",
      "memory usage: 124.9+ KB\n"
     ]
    }
   ],
   "source": [
    "life_sat_total = oecd_bli[oecd_bli[\"INEQUALITY\"]==\"TOT\"]\n",
    "life_sat_total.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "426e54c9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 24 entries, 1 to 3182\n",
      "Data columns (total 17 columns):\n",
      " #   Column                 Non-Null Count  Dtype  \n",
      "---  ------                 --------------  -----  \n",
      " 0   LOCATION               24 non-null     object \n",
      " 1   Country                24 non-null     object \n",
      " 2   INDICATOR              24 non-null     object \n",
      " 3   Indicator              24 non-null     object \n",
      " 4   MEASURE                24 non-null     object \n",
      " 5   Measure                24 non-null     object \n",
      " 6   INEQUALITY             24 non-null     object \n",
      " 7   Inequality             24 non-null     object \n",
      " 8   Unit Code              24 non-null     object \n",
      " 9   Unit                   24 non-null     object \n",
      " 10  PowerCode Code         24 non-null     int64  \n",
      " 11  PowerCode              24 non-null     object \n",
      " 12  Reference Period Code  0 non-null      float64\n",
      " 13  Reference Period       0 non-null      float64\n",
      " 14  Value                  24 non-null     float64\n",
      " 15  Flag Codes             0 non-null      object \n",
      " 16  Flags                  0 non-null      object \n",
      "dtypes: float64(3), int64(1), object(13)\n",
      "memory usage: 3.4+ KB\n"
     ]
    }
   ],
   "source": [
    "new = life_sat_total[life_sat_total[\"Country\"]=='Austria']\n",
    "new.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "20e499fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>Indicator</th>\n",
       "      <th>Air pollution</th>\n",
       "      <th>Assault rate</th>\n",
       "      <th>Consultation on rule-making</th>\n",
       "      <th>Dwellings without basic facilities</th>\n",
       "      <th>Educational attainment</th>\n",
       "      <th>Employees working very long hours</th>\n",
       "      <th>Employment rate</th>\n",
       "      <th>Homicide rate</th>\n",
       "      <th>Household net adjusted disposable income</th>\n",
       "      <th>Household net financial wealth</th>\n",
       "      <th>...</th>\n",
       "      <th>Long-term unemployment rate</th>\n",
       "      <th>Personal earnings</th>\n",
       "      <th>Quality of support network</th>\n",
       "      <th>Rooms per person</th>\n",
       "      <th>Self-reported health</th>\n",
       "      <th>Student skills</th>\n",
       "      <th>Time devoted to leisure and personal care</th>\n",
       "      <th>Voter turnout</th>\n",
       "      <th>Water quality</th>\n",
       "      <th>Years in education</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Country</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Australia</th>\n",
       "      <td>13.0</td>\n",
       "      <td>2.1</td>\n",
       "      <td>10.5</td>\n",
       "      <td>1.1</td>\n",
       "      <td>76.0</td>\n",
       "      <td>14.02</td>\n",
       "      <td>72.0</td>\n",
       "      <td>0.8</td>\n",
       "      <td>31588.0</td>\n",
       "      <td>47657.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.08</td>\n",
       "      <td>50449.0</td>\n",
       "      <td>92.0</td>\n",
       "      <td>2.3</td>\n",
       "      <td>85.0</td>\n",
       "      <td>512.0</td>\n",
       "      <td>14.41</td>\n",
       "      <td>93.0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>19.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austria</th>\n",
       "      <td>27.0</td>\n",
       "      <td>3.4</td>\n",
       "      <td>7.1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>7.61</td>\n",
       "      <td>72.0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>31173.0</td>\n",
       "      <td>49887.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.19</td>\n",
       "      <td>45199.0</td>\n",
       "      <td>89.0</td>\n",
       "      <td>1.6</td>\n",
       "      <td>69.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>14.46</td>\n",
       "      <td>75.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>17.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Belgium</th>\n",
       "      <td>21.0</td>\n",
       "      <td>6.6</td>\n",
       "      <td>4.5</td>\n",
       "      <td>2.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>4.57</td>\n",
       "      <td>62.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>28307.0</td>\n",
       "      <td>83876.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.88</td>\n",
       "      <td>48082.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>2.2</td>\n",
       "      <td>74.0</td>\n",
       "      <td>509.0</td>\n",
       "      <td>15.71</td>\n",
       "      <td>89.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>18.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Brazil</th>\n",
       "      <td>18.0</td>\n",
       "      <td>7.9</td>\n",
       "      <td>4.0</td>\n",
       "      <td>6.7</td>\n",
       "      <td>45.0</td>\n",
       "      <td>10.41</td>\n",
       "      <td>67.0</td>\n",
       "      <td>25.5</td>\n",
       "      <td>11664.0</td>\n",
       "      <td>6844.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.97</td>\n",
       "      <td>17177.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>1.6</td>\n",
       "      <td>69.0</td>\n",
       "      <td>402.0</td>\n",
       "      <td>14.97</td>\n",
       "      <td>79.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>16.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Canada</th>\n",
       "      <td>15.0</td>\n",
       "      <td>1.3</td>\n",
       "      <td>10.5</td>\n",
       "      <td>0.2</td>\n",
       "      <td>89.0</td>\n",
       "      <td>3.94</td>\n",
       "      <td>72.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>29365.0</td>\n",
       "      <td>67913.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.90</td>\n",
       "      <td>46911.0</td>\n",
       "      <td>92.0</td>\n",
       "      <td>2.5</td>\n",
       "      <td>89.0</td>\n",
       "      <td>522.0</td>\n",
       "      <td>14.25</td>\n",
       "      <td>61.0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>17.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chile</th>\n",
       "      <td>46.0</td>\n",
       "      <td>6.9</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.4</td>\n",
       "      <td>57.0</td>\n",
       "      <td>15.42</td>\n",
       "      <td>62.0</td>\n",
       "      <td>4.4</td>\n",
       "      <td>14533.0</td>\n",
       "      <td>17733.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.59</td>\n",
       "      <td>22101.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>1.2</td>\n",
       "      <td>59.0</td>\n",
       "      <td>436.0</td>\n",
       "      <td>14.41</td>\n",
       "      <td>49.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>16.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Czech Republic</th>\n",
       "      <td>16.0</td>\n",
       "      <td>2.8</td>\n",
       "      <td>6.8</td>\n",
       "      <td>0.9</td>\n",
       "      <td>92.0</td>\n",
       "      <td>6.98</td>\n",
       "      <td>68.0</td>\n",
       "      <td>0.8</td>\n",
       "      <td>18404.0</td>\n",
       "      <td>17299.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.12</td>\n",
       "      <td>20338.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>60.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>14.98</td>\n",
       "      <td>59.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>18.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Denmark</th>\n",
       "      <td>15.0</td>\n",
       "      <td>3.9</td>\n",
       "      <td>7.0</td>\n",
       "      <td>0.9</td>\n",
       "      <td>78.0</td>\n",
       "      <td>2.03</td>\n",
       "      <td>73.0</td>\n",
       "      <td>0.3</td>\n",
       "      <td>26491.0</td>\n",
       "      <td>44488.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.78</td>\n",
       "      <td>48347.0</td>\n",
       "      <td>95.0</td>\n",
       "      <td>1.9</td>\n",
       "      <td>72.0</td>\n",
       "      <td>498.0</td>\n",
       "      <td>16.06</td>\n",
       "      <td>88.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>19.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Estonia</th>\n",
       "      <td>9.0</td>\n",
       "      <td>5.5</td>\n",
       "      <td>3.3</td>\n",
       "      <td>8.1</td>\n",
       "      <td>90.0</td>\n",
       "      <td>3.30</td>\n",
       "      <td>68.0</td>\n",
       "      <td>4.8</td>\n",
       "      <td>15167.0</td>\n",
       "      <td>7680.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.82</td>\n",
       "      <td>18944.0</td>\n",
       "      <td>89.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>54.0</td>\n",
       "      <td>526.0</td>\n",
       "      <td>14.90</td>\n",
       "      <td>64.0</td>\n",
       "      <td>79.0</td>\n",
       "      <td>17.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Finland</th>\n",
       "      <td>15.0</td>\n",
       "      <td>2.4</td>\n",
       "      <td>9.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>85.0</td>\n",
       "      <td>3.58</td>\n",
       "      <td>69.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>27927.0</td>\n",
       "      <td>18761.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.73</td>\n",
       "      <td>40060.0</td>\n",
       "      <td>95.0</td>\n",
       "      <td>1.9</td>\n",
       "      <td>65.0</td>\n",
       "      <td>529.0</td>\n",
       "      <td>14.89</td>\n",
       "      <td>69.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>19.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>France</th>\n",
       "      <td>12.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>3.5</td>\n",
       "      <td>0.5</td>\n",
       "      <td>73.0</td>\n",
       "      <td>8.15</td>\n",
       "      <td>64.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>28799.0</td>\n",
       "      <td>48741.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.99</td>\n",
       "      <td>40242.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>1.8</td>\n",
       "      <td>67.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>15.33</td>\n",
       "      <td>80.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>16.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Germany</th>\n",
       "      <td>16.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>4.5</td>\n",
       "      <td>0.1</td>\n",
       "      <td>86.0</td>\n",
       "      <td>5.25</td>\n",
       "      <td>73.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>31252.0</td>\n",
       "      <td>50394.0</td>\n",
       "      <td>...</td>\n",
       "      <td>2.37</td>\n",
       "      <td>43682.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>1.8</td>\n",
       "      <td>65.0</td>\n",
       "      <td>515.0</td>\n",
       "      <td>15.31</td>\n",
       "      <td>72.0</td>\n",
       "      <td>95.0</td>\n",
       "      <td>18.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Greece</th>\n",
       "      <td>27.0</td>\n",
       "      <td>3.7</td>\n",
       "      <td>6.5</td>\n",
       "      <td>0.7</td>\n",
       "      <td>68.0</td>\n",
       "      <td>6.16</td>\n",
       "      <td>49.0</td>\n",
       "      <td>1.6</td>\n",
       "      <td>18575.0</td>\n",
       "      <td>14579.0</td>\n",
       "      <td>...</td>\n",
       "      <td>18.39</td>\n",
       "      <td>25503.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>1.2</td>\n",
       "      <td>74.0</td>\n",
       "      <td>466.0</td>\n",
       "      <td>14.91</td>\n",
       "      <td>64.0</td>\n",
       "      <td>69.0</td>\n",
       "      <td>18.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hungary</th>\n",
       "      <td>15.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>7.9</td>\n",
       "      <td>4.8</td>\n",
       "      <td>82.0</td>\n",
       "      <td>3.19</td>\n",
       "      <td>58.0</td>\n",
       "      <td>1.3</td>\n",
       "      <td>15442.0</td>\n",
       "      <td>13277.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5.10</td>\n",
       "      <td>20948.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>57.0</td>\n",
       "      <td>487.0</td>\n",
       "      <td>15.04</td>\n",
       "      <td>62.0</td>\n",
       "      <td>77.0</td>\n",
       "      <td>17.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iceland</th>\n",
       "      <td>18.0</td>\n",
       "      <td>2.7</td>\n",
       "      <td>5.1</td>\n",
       "      <td>0.4</td>\n",
       "      <td>71.0</td>\n",
       "      <td>12.25</td>\n",
       "      <td>82.0</td>\n",
       "      <td>0.3</td>\n",
       "      <td>23965.0</td>\n",
       "      <td>43045.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.18</td>\n",
       "      <td>55716.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>77.0</td>\n",
       "      <td>484.0</td>\n",
       "      <td>14.61</td>\n",
       "      <td>81.0</td>\n",
       "      <td>97.0</td>\n",
       "      <td>19.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ireland</th>\n",
       "      <td>13.0</td>\n",
       "      <td>2.6</td>\n",
       "      <td>9.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>75.0</td>\n",
       "      <td>4.20</td>\n",
       "      <td>60.0</td>\n",
       "      <td>0.8</td>\n",
       "      <td>23917.0</td>\n",
       "      <td>31580.0</td>\n",
       "      <td>...</td>\n",
       "      <td>8.39</td>\n",
       "      <td>49506.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>2.1</td>\n",
       "      <td>82.0</td>\n",
       "      <td>516.0</td>\n",
       "      <td>15.19</td>\n",
       "      <td>70.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>17.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Israel</th>\n",
       "      <td>21.0</td>\n",
       "      <td>6.4</td>\n",
       "      <td>2.5</td>\n",
       "      <td>3.7</td>\n",
       "      <td>85.0</td>\n",
       "      <td>16.03</td>\n",
       "      <td>67.0</td>\n",
       "      <td>2.3</td>\n",
       "      <td>22104.0</td>\n",
       "      <td>52933.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.79</td>\n",
       "      <td>28817.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>1.2</td>\n",
       "      <td>80.0</td>\n",
       "      <td>474.0</td>\n",
       "      <td>14.48</td>\n",
       "      <td>68.0</td>\n",
       "      <td>68.0</td>\n",
       "      <td>15.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Italy</th>\n",
       "      <td>21.0</td>\n",
       "      <td>4.7</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>57.0</td>\n",
       "      <td>3.66</td>\n",
       "      <td>56.0</td>\n",
       "      <td>0.7</td>\n",
       "      <td>25166.0</td>\n",
       "      <td>54987.0</td>\n",
       "      <td>...</td>\n",
       "      <td>6.94</td>\n",
       "      <td>34561.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>66.0</td>\n",
       "      <td>490.0</td>\n",
       "      <td>14.98</td>\n",
       "      <td>75.0</td>\n",
       "      <td>71.0</td>\n",
       "      <td>16.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Japan</th>\n",
       "      <td>24.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>7.3</td>\n",
       "      <td>6.4</td>\n",
       "      <td>94.0</td>\n",
       "      <td>22.26</td>\n",
       "      <td>72.0</td>\n",
       "      <td>0.3</td>\n",
       "      <td>26111.0</td>\n",
       "      <td>86764.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.67</td>\n",
       "      <td>35405.0</td>\n",
       "      <td>89.0</td>\n",
       "      <td>1.8</td>\n",
       "      <td>30.0</td>\n",
       "      <td>540.0</td>\n",
       "      <td>14.93</td>\n",
       "      <td>53.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>16.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Korea</th>\n",
       "      <td>30.0</td>\n",
       "      <td>2.1</td>\n",
       "      <td>10.4</td>\n",
       "      <td>4.2</td>\n",
       "      <td>82.0</td>\n",
       "      <td>18.72</td>\n",
       "      <td>64.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>19510.0</td>\n",
       "      <td>29091.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.01</td>\n",
       "      <td>36354.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>35.0</td>\n",
       "      <td>542.0</td>\n",
       "      <td>14.63</td>\n",
       "      <td>76.0</td>\n",
       "      <td>78.0</td>\n",
       "      <td>17.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Luxembourg</th>\n",
       "      <td>12.0</td>\n",
       "      <td>4.3</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.1</td>\n",
       "      <td>78.0</td>\n",
       "      <td>3.47</td>\n",
       "      <td>66.0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>38951.0</td>\n",
       "      <td>61765.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.78</td>\n",
       "      <td>56021.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>490.0</td>\n",
       "      <td>15.12</td>\n",
       "      <td>91.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>15.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Mexico</th>\n",
       "      <td>30.0</td>\n",
       "      <td>12.8</td>\n",
       "      <td>9.0</td>\n",
       "      <td>4.2</td>\n",
       "      <td>37.0</td>\n",
       "      <td>28.83</td>\n",
       "      <td>61.0</td>\n",
       "      <td>23.4</td>\n",
       "      <td>13085.0</td>\n",
       "      <td>9056.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.08</td>\n",
       "      <td>16193.0</td>\n",
       "      <td>77.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>417.0</td>\n",
       "      <td>13.89</td>\n",
       "      <td>63.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>14.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Netherlands</th>\n",
       "      <td>30.0</td>\n",
       "      <td>4.9</td>\n",
       "      <td>6.1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>74.0</td>\n",
       "      <td>0.9</td>\n",
       "      <td>27888.0</td>\n",
       "      <td>77961.0</td>\n",
       "      <td>...</td>\n",
       "      <td>2.40</td>\n",
       "      <td>47590.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>519.0</td>\n",
       "      <td>15.44</td>\n",
       "      <td>75.0</td>\n",
       "      <td>92.0</td>\n",
       "      <td>18.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Zealand</th>\n",
       "      <td>11.0</td>\n",
       "      <td>2.2</td>\n",
       "      <td>10.3</td>\n",
       "      <td>0.2</td>\n",
       "      <td>74.0</td>\n",
       "      <td>13.87</td>\n",
       "      <td>73.0</td>\n",
       "      <td>1.2</td>\n",
       "      <td>23815.0</td>\n",
       "      <td>28290.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.75</td>\n",
       "      <td>35609.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>2.4</td>\n",
       "      <td>90.0</td>\n",
       "      <td>509.0</td>\n",
       "      <td>14.87</td>\n",
       "      <td>77.0</td>\n",
       "      <td>89.0</td>\n",
       "      <td>18.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Norway</th>\n",
       "      <td>16.0</td>\n",
       "      <td>3.3</td>\n",
       "      <td>8.1</td>\n",
       "      <td>0.3</td>\n",
       "      <td>82.0</td>\n",
       "      <td>2.82</td>\n",
       "      <td>75.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>33492.0</td>\n",
       "      <td>8797.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.32</td>\n",
       "      <td>50282.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>496.0</td>\n",
       "      <td>15.56</td>\n",
       "      <td>78.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>17.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OECD - Total</th>\n",
       "      <td>20.0</td>\n",
       "      <td>3.9</td>\n",
       "      <td>7.3</td>\n",
       "      <td>2.4</td>\n",
       "      <td>75.0</td>\n",
       "      <td>12.51</td>\n",
       "      <td>65.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>25908.0</td>\n",
       "      <td>67139.0</td>\n",
       "      <td>...</td>\n",
       "      <td>2.79</td>\n",
       "      <td>36118.0</td>\n",
       "      <td>88.0</td>\n",
       "      <td>1.8</td>\n",
       "      <td>68.0</td>\n",
       "      <td>497.0</td>\n",
       "      <td>14.97</td>\n",
       "      <td>68.0</td>\n",
       "      <td>81.0</td>\n",
       "      <td>17.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Poland</th>\n",
       "      <td>33.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>10.8</td>\n",
       "      <td>3.2</td>\n",
       "      <td>90.0</td>\n",
       "      <td>7.41</td>\n",
       "      <td>60.0</td>\n",
       "      <td>0.9</td>\n",
       "      <td>17852.0</td>\n",
       "      <td>10919.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.77</td>\n",
       "      <td>22655.0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>58.0</td>\n",
       "      <td>521.0</td>\n",
       "      <td>14.20</td>\n",
       "      <td>55.0</td>\n",
       "      <td>79.0</td>\n",
       "      <td>18.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Portugal</th>\n",
       "      <td>18.0</td>\n",
       "      <td>5.7</td>\n",
       "      <td>6.5</td>\n",
       "      <td>0.9</td>\n",
       "      <td>38.0</td>\n",
       "      <td>9.62</td>\n",
       "      <td>61.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>20086.0</td>\n",
       "      <td>31245.0</td>\n",
       "      <td>...</td>\n",
       "      <td>9.11</td>\n",
       "      <td>23688.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>1.6</td>\n",
       "      <td>46.0</td>\n",
       "      <td>488.0</td>\n",
       "      <td>14.95</td>\n",
       "      <td>58.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>17.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Russia</th>\n",
       "      <td>15.0</td>\n",
       "      <td>3.8</td>\n",
       "      <td>2.5</td>\n",
       "      <td>15.1</td>\n",
       "      <td>94.0</td>\n",
       "      <td>0.16</td>\n",
       "      <td>69.0</td>\n",
       "      <td>12.8</td>\n",
       "      <td>19292.0</td>\n",
       "      <td>3412.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.70</td>\n",
       "      <td>20885.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>0.9</td>\n",
       "      <td>37.0</td>\n",
       "      <td>481.0</td>\n",
       "      <td>14.97</td>\n",
       "      <td>65.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>16.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Slovak Republic</th>\n",
       "      <td>13.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>6.6</td>\n",
       "      <td>0.6</td>\n",
       "      <td>92.0</td>\n",
       "      <td>7.02</td>\n",
       "      <td>60.0</td>\n",
       "      <td>1.2</td>\n",
       "      <td>17503.0</td>\n",
       "      <td>8663.0</td>\n",
       "      <td>...</td>\n",
       "      <td>9.46</td>\n",
       "      <td>20307.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>66.0</td>\n",
       "      <td>472.0</td>\n",
       "      <td>14.99</td>\n",
       "      <td>59.0</td>\n",
       "      <td>81.0</td>\n",
       "      <td>16.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Slovenia</th>\n",
       "      <td>26.0</td>\n",
       "      <td>3.9</td>\n",
       "      <td>10.3</td>\n",
       "      <td>0.5</td>\n",
       "      <td>85.0</td>\n",
       "      <td>5.63</td>\n",
       "      <td>63.0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>19326.0</td>\n",
       "      <td>18465.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5.15</td>\n",
       "      <td>32037.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>65.0</td>\n",
       "      <td>499.0</td>\n",
       "      <td>14.62</td>\n",
       "      <td>52.0</td>\n",
       "      <td>88.0</td>\n",
       "      <td>18.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spain</th>\n",
       "      <td>24.0</td>\n",
       "      <td>4.2</td>\n",
       "      <td>7.3</td>\n",
       "      <td>0.1</td>\n",
       "      <td>55.0</td>\n",
       "      <td>5.89</td>\n",
       "      <td>56.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>22477.0</td>\n",
       "      <td>24774.0</td>\n",
       "      <td>...</td>\n",
       "      <td>12.96</td>\n",
       "      <td>34824.0</td>\n",
       "      <td>95.0</td>\n",
       "      <td>1.9</td>\n",
       "      <td>72.0</td>\n",
       "      <td>490.0</td>\n",
       "      <td>16.06</td>\n",
       "      <td>69.0</td>\n",
       "      <td>71.0</td>\n",
       "      <td>17.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sweden</th>\n",
       "      <td>10.0</td>\n",
       "      <td>5.1</td>\n",
       "      <td>10.9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>88.0</td>\n",
       "      <td>1.13</td>\n",
       "      <td>74.0</td>\n",
       "      <td>0.7</td>\n",
       "      <td>29185.0</td>\n",
       "      <td>60328.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.37</td>\n",
       "      <td>40818.0</td>\n",
       "      <td>92.0</td>\n",
       "      <td>1.7</td>\n",
       "      <td>81.0</td>\n",
       "      <td>482.0</td>\n",
       "      <td>15.11</td>\n",
       "      <td>86.0</td>\n",
       "      <td>95.0</td>\n",
       "      <td>19.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Switzerland</th>\n",
       "      <td>20.0</td>\n",
       "      <td>4.2</td>\n",
       "      <td>8.4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>6.72</td>\n",
       "      <td>80.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>33491.0</td>\n",
       "      <td>108823.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.46</td>\n",
       "      <td>54236.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>1.8</td>\n",
       "      <td>81.0</td>\n",
       "      <td>518.0</td>\n",
       "      <td>14.98</td>\n",
       "      <td>49.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>17.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Turkey</th>\n",
       "      <td>35.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.5</td>\n",
       "      <td>12.7</td>\n",
       "      <td>34.0</td>\n",
       "      <td>40.86</td>\n",
       "      <td>50.0</td>\n",
       "      <td>1.2</td>\n",
       "      <td>14095.0</td>\n",
       "      <td>3251.0</td>\n",
       "      <td>...</td>\n",
       "      <td>2.37</td>\n",
       "      <td>16919.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>68.0</td>\n",
       "      <td>462.0</td>\n",
       "      <td>13.42</td>\n",
       "      <td>88.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>16.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United Kingdom</th>\n",
       "      <td>13.0</td>\n",
       "      <td>1.9</td>\n",
       "      <td>11.5</td>\n",
       "      <td>0.2</td>\n",
       "      <td>78.0</td>\n",
       "      <td>12.70</td>\n",
       "      <td>71.0</td>\n",
       "      <td>0.3</td>\n",
       "      <td>27029.0</td>\n",
       "      <td>60778.0</td>\n",
       "      <td>...</td>\n",
       "      <td>2.77</td>\n",
       "      <td>41192.0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>1.9</td>\n",
       "      <td>74.0</td>\n",
       "      <td>502.0</td>\n",
       "      <td>14.83</td>\n",
       "      <td>66.0</td>\n",
       "      <td>88.0</td>\n",
       "      <td>16.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United States</th>\n",
       "      <td>18.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>8.3</td>\n",
       "      <td>0.1</td>\n",
       "      <td>89.0</td>\n",
       "      <td>11.30</td>\n",
       "      <td>67.0</td>\n",
       "      <td>5.2</td>\n",
       "      <td>41355.0</td>\n",
       "      <td>145769.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.91</td>\n",
       "      <td>56340.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2.4</td>\n",
       "      <td>88.0</td>\n",
       "      <td>492.0</td>\n",
       "      <td>14.27</td>\n",
       "      <td>68.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>17.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>37 rows × 24 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Indicator        Air pollution  Assault rate  Consultation on rule-making  \\\n",
       "Country                                                                     \n",
       "Australia                 13.0           2.1                         10.5   \n",
       "Austria                   27.0           3.4                          7.1   \n",
       "Belgium                   21.0           6.6                          4.5   \n",
       "Brazil                    18.0           7.9                          4.0   \n",
       "Canada                    15.0           1.3                         10.5   \n",
       "Chile                     46.0           6.9                          2.0   \n",
       "Czech Republic            16.0           2.8                          6.8   \n",
       "Denmark                   15.0           3.9                          7.0   \n",
       "Estonia                    9.0           5.5                          3.3   \n",
       "Finland                   15.0           2.4                          9.0   \n",
       "France                    12.0           5.0                          3.5   \n",
       "Germany                   16.0           3.6                          4.5   \n",
       "Greece                    27.0           3.7                          6.5   \n",
       "Hungary                   15.0           3.6                          7.9   \n",
       "Iceland                   18.0           2.7                          5.1   \n",
       "Ireland                   13.0           2.6                          9.0   \n",
       "Israel                    21.0           6.4                          2.5   \n",
       "Italy                     21.0           4.7                          5.0   \n",
       "Japan                     24.0           1.4                          7.3   \n",
       "Korea                     30.0           2.1                         10.4   \n",
       "Luxembourg                12.0           4.3                          6.0   \n",
       "Mexico                    30.0          12.8                          9.0   \n",
       "Netherlands               30.0           4.9                          6.1   \n",
       "New Zealand               11.0           2.2                         10.3   \n",
       "Norway                    16.0           3.3                          8.1   \n",
       "OECD - Total              20.0           3.9                          7.3   \n",
       "Poland                    33.0           1.4                         10.8   \n",
       "Portugal                  18.0           5.7                          6.5   \n",
       "Russia                    15.0           3.8                          2.5   \n",
       "Slovak Republic           13.0           3.0                          6.6   \n",
       "Slovenia                  26.0           3.9                         10.3   \n",
       "Spain                     24.0           4.2                          7.3   \n",
       "Sweden                    10.0           5.1                         10.9   \n",
       "Switzerland               20.0           4.2                          8.4   \n",
       "Turkey                    35.0           5.0                          5.5   \n",
       "United Kingdom            13.0           1.9                         11.5   \n",
       "United States             18.0           1.5                          8.3   \n",
       "\n",
       "Indicator        Dwellings without basic facilities  Educational attainment  \\\n",
       "Country                                                                       \n",
       "Australia                                       1.1                    76.0   \n",
       "Austria                                         1.0                    83.0   \n",
       "Belgium                                         2.0                    72.0   \n",
       "Brazil                                          6.7                    45.0   \n",
       "Canada                                          0.2                    89.0   \n",
       "Chile                                           9.4                    57.0   \n",
       "Czech Republic                                  0.9                    92.0   \n",
       "Denmark                                         0.9                    78.0   \n",
       "Estonia                                         8.1                    90.0   \n",
       "Finland                                         0.6                    85.0   \n",
       "France                                          0.5                    73.0   \n",
       "Germany                                         0.1                    86.0   \n",
       "Greece                                          0.7                    68.0   \n",
       "Hungary                                         4.8                    82.0   \n",
       "Iceland                                         0.4                    71.0   \n",
       "Ireland                                         0.2                    75.0   \n",
       "Israel                                          3.7                    85.0   \n",
       "Italy                                           1.1                    57.0   \n",
       "Japan                                           6.4                    94.0   \n",
       "Korea                                           4.2                    82.0   \n",
       "Luxembourg                                      0.1                    78.0   \n",
       "Mexico                                          4.2                    37.0   \n",
       "Netherlands                                     0.0                    73.0   \n",
       "New Zealand                                     0.2                    74.0   \n",
       "Norway                                          0.3                    82.0   \n",
       "OECD - Total                                    2.4                    75.0   \n",
       "Poland                                          3.2                    90.0   \n",
       "Portugal                                        0.9                    38.0   \n",
       "Russia                                         15.1                    94.0   \n",
       "Slovak Republic                                 0.6                    92.0   \n",
       "Slovenia                                        0.5                    85.0   \n",
       "Spain                                           0.1                    55.0   \n",
       "Sweden                                          0.0                    88.0   \n",
       "Switzerland                                     0.0                    86.0   \n",
       "Turkey                                         12.7                    34.0   \n",
       "United Kingdom                                  0.2                    78.0   \n",
       "United States                                   0.1                    89.0   \n",
       "\n",
       "Indicator        Employees working very long hours  Employment rate  \\\n",
       "Country                                                               \n",
       "Australia                                    14.02             72.0   \n",
       "Austria                                       7.61             72.0   \n",
       "Belgium                                       4.57             62.0   \n",
       "Brazil                                       10.41             67.0   \n",
       "Canada                                        3.94             72.0   \n",
       "Chile                                        15.42             62.0   \n",
       "Czech Republic                                6.98             68.0   \n",
       "Denmark                                       2.03             73.0   \n",
       "Estonia                                       3.30             68.0   \n",
       "Finland                                       3.58             69.0   \n",
       "France                                        8.15             64.0   \n",
       "Germany                                       5.25             73.0   \n",
       "Greece                                        6.16             49.0   \n",
       "Hungary                                       3.19             58.0   \n",
       "Iceland                                      12.25             82.0   \n",
       "Ireland                                       4.20             60.0   \n",
       "Israel                                       16.03             67.0   \n",
       "Italy                                         3.66             56.0   \n",
       "Japan                                        22.26             72.0   \n",
       "Korea                                        18.72             64.0   \n",
       "Luxembourg                                    3.47             66.0   \n",
       "Mexico                                       28.83             61.0   \n",
       "Netherlands                                   0.45             74.0   \n",
       "New Zealand                                  13.87             73.0   \n",
       "Norway                                        2.82             75.0   \n",
       "OECD - Total                                 12.51             65.0   \n",
       "Poland                                        7.41             60.0   \n",
       "Portugal                                      9.62             61.0   \n",
       "Russia                                        0.16             69.0   \n",
       "Slovak Republic                               7.02             60.0   \n",
       "Slovenia                                      5.63             63.0   \n",
       "Spain                                         5.89             56.0   \n",
       "Sweden                                        1.13             74.0   \n",
       "Switzerland                                   6.72             80.0   \n",
       "Turkey                                       40.86             50.0   \n",
       "United Kingdom                               12.70             71.0   \n",
       "United States                                11.30             67.0   \n",
       "\n",
       "Indicator        Homicide rate  Household net adjusted disposable income  \\\n",
       "Country                                                                    \n",
       "Australia                  0.8                                   31588.0   \n",
       "Austria                    0.4                                   31173.0   \n",
       "Belgium                    1.1                                   28307.0   \n",
       "Brazil                    25.5                                   11664.0   \n",
       "Canada                     1.5                                   29365.0   \n",
       "Chile                      4.4                                   14533.0   \n",
       "Czech Republic             0.8                                   18404.0   \n",
       "Denmark                    0.3                                   26491.0   \n",
       "Estonia                    4.8                                   15167.0   \n",
       "Finland                    1.4                                   27927.0   \n",
       "France                     0.6                                   28799.0   \n",
       "Germany                    0.5                                   31252.0   \n",
       "Greece                     1.6                                   18575.0   \n",
       "Hungary                    1.3                                   15442.0   \n",
       "Iceland                    0.3                                   23965.0   \n",
       "Ireland                    0.8                                   23917.0   \n",
       "Israel                     2.3                                   22104.0   \n",
       "Italy                      0.7                                   25166.0   \n",
       "Japan                      0.3                                   26111.0   \n",
       "Korea                      1.1                                   19510.0   \n",
       "Luxembourg                 0.4                                   38951.0   \n",
       "Mexico                    23.4                                   13085.0   \n",
       "Netherlands                0.9                                   27888.0   \n",
       "New Zealand                1.2                                   23815.0   \n",
       "Norway                     0.6                                   33492.0   \n",
       "OECD - Total               4.0                                   25908.0   \n",
       "Poland                     0.9                                   17852.0   \n",
       "Portugal                   1.1                                   20086.0   \n",
       "Russia                    12.8                                   19292.0   \n",
       "Slovak Republic            1.2                                   17503.0   \n",
       "Slovenia                   0.4                                   19326.0   \n",
       "Spain                      0.6                                   22477.0   \n",
       "Sweden                     0.7                                   29185.0   \n",
       "Switzerland                0.5                                   33491.0   \n",
       "Turkey                     1.2                                   14095.0   \n",
       "United Kingdom             0.3                                   27029.0   \n",
       "United States              5.2                                   41355.0   \n",
       "\n",
       "Indicator        Household net financial wealth  ...  \\\n",
       "Country                                          ...   \n",
       "Australia                               47657.0  ...   \n",
       "Austria                                 49887.0  ...   \n",
       "Belgium                                 83876.0  ...   \n",
       "Brazil                                   6844.0  ...   \n",
       "Canada                                  67913.0  ...   \n",
       "Chile                                   17733.0  ...   \n",
       "Czech Republic                          17299.0  ...   \n",
       "Denmark                                 44488.0  ...   \n",
       "Estonia                                  7680.0  ...   \n",
       "Finland                                 18761.0  ...   \n",
       "France                                  48741.0  ...   \n",
       "Germany                                 50394.0  ...   \n",
       "Greece                                  14579.0  ...   \n",
       "Hungary                                 13277.0  ...   \n",
       "Iceland                                 43045.0  ...   \n",
       "Ireland                                 31580.0  ...   \n",
       "Israel                                  52933.0  ...   \n",
       "Italy                                   54987.0  ...   \n",
       "Japan                                   86764.0  ...   \n",
       "Korea                                   29091.0  ...   \n",
       "Luxembourg                              61765.0  ...   \n",
       "Mexico                                   9056.0  ...   \n",
       "Netherlands                             77961.0  ...   \n",
       "New Zealand                             28290.0  ...   \n",
       "Norway                                   8797.0  ...   \n",
       "OECD - Total                            67139.0  ...   \n",
       "Poland                                  10919.0  ...   \n",
       "Portugal                                31245.0  ...   \n",
       "Russia                                   3412.0  ...   \n",
       "Slovak Republic                          8663.0  ...   \n",
       "Slovenia                                18465.0  ...   \n",
       "Spain                                   24774.0  ...   \n",
       "Sweden                                  60328.0  ...   \n",
       "Switzerland                            108823.0  ...   \n",
       "Turkey                                   3251.0  ...   \n",
       "United Kingdom                          60778.0  ...   \n",
       "United States                          145769.0  ...   \n",
       "\n",
       "Indicator        Long-term unemployment rate  Personal earnings  \\\n",
       "Country                                                           \n",
       "Australia                               1.08            50449.0   \n",
       "Austria                                 1.19            45199.0   \n",
       "Belgium                                 3.88            48082.0   \n",
       "Brazil                                  1.97            17177.0   \n",
       "Canada                                  0.90            46911.0   \n",
       "Chile                                   1.59            22101.0   \n",
       "Czech Republic                          3.12            20338.0   \n",
       "Denmark                                 1.78            48347.0   \n",
       "Estonia                                 3.82            18944.0   \n",
       "Finland                                 1.73            40060.0   \n",
       "France                                  3.99            40242.0   \n",
       "Germany                                 2.37            43682.0   \n",
       "Greece                                 18.39            25503.0   \n",
       "Hungary                                 5.10            20948.0   \n",
       "Iceland                                 1.18            55716.0   \n",
       "Ireland                                 8.39            49506.0   \n",
       "Israel                                  0.79            28817.0   \n",
       "Italy                                   6.94            34561.0   \n",
       "Japan                                   1.67            35405.0   \n",
       "Korea                                   0.01            36354.0   \n",
       "Luxembourg                              1.78            56021.0   \n",
       "Mexico                                  0.08            16193.0   \n",
       "Netherlands                             2.40            47590.0   \n",
       "New Zealand                             0.75            35609.0   \n",
       "Norway                                  0.32            50282.0   \n",
       "OECD - Total                            2.79            36118.0   \n",
       "Poland                                  3.77            22655.0   \n",
       "Portugal                                9.11            23688.0   \n",
       "Russia                                  1.70            20885.0   \n",
       "Slovak Republic                         9.46            20307.0   \n",
       "Slovenia                                5.15            32037.0   \n",
       "Spain                                  12.96            34824.0   \n",
       "Sweden                                  1.37            40818.0   \n",
       "Switzerland                             1.46            54236.0   \n",
       "Turkey                                  2.37            16919.0   \n",
       "United Kingdom                          2.77            41192.0   \n",
       "United States                           1.91            56340.0   \n",
       "\n",
       "Indicator        Quality of support network  Rooms per person  \\\n",
       "Country                                                         \n",
       "Australia                              92.0               2.3   \n",
       "Austria                                89.0               1.6   \n",
       "Belgium                                94.0               2.2   \n",
       "Brazil                                 90.0               1.6   \n",
       "Canada                                 92.0               2.5   \n",
       "Chile                                  86.0               1.2   \n",
       "Czech Republic                         85.0               1.4   \n",
       "Denmark                                95.0               1.9   \n",
       "Estonia                                89.0               1.5   \n",
       "Finland                                95.0               1.9   \n",
       "France                                 87.0               1.8   \n",
       "Germany                                94.0               1.8   \n",
       "Greece                                 83.0               1.2   \n",
       "Hungary                                87.0               1.1   \n",
       "Iceland                                96.0               1.5   \n",
       "Ireland                                96.0               2.1   \n",
       "Israel                                 87.0               1.2   \n",
       "Italy                                  90.0               1.4   \n",
       "Japan                                  89.0               1.8   \n",
       "Korea                                  72.0               1.4   \n",
       "Luxembourg                             87.0               2.0   \n",
       "Mexico                                 77.0               1.0   \n",
       "Netherlands                            90.0               2.0   \n",
       "New Zealand                            94.0               2.4   \n",
       "Norway                                 94.0               2.0   \n",
       "OECD - Total                           88.0               1.8   \n",
       "Poland                                 91.0               1.1   \n",
       "Portugal                               86.0               1.6   \n",
       "Russia                                 90.0               0.9   \n",
       "Slovak Republic                        90.0               1.1   \n",
       "Slovenia                               90.0               1.5   \n",
       "Spain                                  95.0               1.9   \n",
       "Sweden                                 92.0               1.7   \n",
       "Switzerland                            96.0               1.8   \n",
       "Turkey                                 86.0               1.1   \n",
       "United Kingdom                         91.0               1.9   \n",
       "United States                          90.0               2.4   \n",
       "\n",
       "Indicator        Self-reported health  Student skills  \\\n",
       "Country                                                 \n",
       "Australia                        85.0           512.0   \n",
       "Austria                          69.0           500.0   \n",
       "Belgium                          74.0           509.0   \n",
       "Brazil                           69.0           402.0   \n",
       "Canada                           89.0           522.0   \n",
       "Chile                            59.0           436.0   \n",
       "Czech Republic                   60.0           500.0   \n",
       "Denmark                          72.0           498.0   \n",
       "Estonia                          54.0           526.0   \n",
       "Finland                          65.0           529.0   \n",
       "France                           67.0           500.0   \n",
       "Germany                          65.0           515.0   \n",
       "Greece                           74.0           466.0   \n",
       "Hungary                          57.0           487.0   \n",
       "Iceland                          77.0           484.0   \n",
       "Ireland                          82.0           516.0   \n",
       "Israel                           80.0           474.0   \n",
       "Italy                            66.0           490.0   \n",
       "Japan                            30.0           540.0   \n",
       "Korea                            35.0           542.0   \n",
       "Luxembourg                       72.0           490.0   \n",
       "Mexico                           66.0           417.0   \n",
       "Netherlands                      76.0           519.0   \n",
       "New Zealand                      90.0           509.0   \n",
       "Norway                           76.0           496.0   \n",
       "OECD - Total                     68.0           497.0   \n",
       "Poland                           58.0           521.0   \n",
       "Portugal                         46.0           488.0   \n",
       "Russia                           37.0           481.0   \n",
       "Slovak Republic                  66.0           472.0   \n",
       "Slovenia                         65.0           499.0   \n",
       "Spain                            72.0           490.0   \n",
       "Sweden                           81.0           482.0   \n",
       "Switzerland                      81.0           518.0   \n",
       "Turkey                           68.0           462.0   \n",
       "United Kingdom                   74.0           502.0   \n",
       "United States                    88.0           492.0   \n",
       "\n",
       "Indicator        Time devoted to leisure and personal care  Voter turnout  \\\n",
       "Country                                                                     \n",
       "Australia                                            14.41           93.0   \n",
       "Austria                                              14.46           75.0   \n",
       "Belgium                                              15.71           89.0   \n",
       "Brazil                                               14.97           79.0   \n",
       "Canada                                               14.25           61.0   \n",
       "Chile                                                14.41           49.0   \n",
       "Czech Republic                                       14.98           59.0   \n",
       "Denmark                                              16.06           88.0   \n",
       "Estonia                                              14.90           64.0   \n",
       "Finland                                              14.89           69.0   \n",
       "France                                               15.33           80.0   \n",
       "Germany                                              15.31           72.0   \n",
       "Greece                                               14.91           64.0   \n",
       "Hungary                                              15.04           62.0   \n",
       "Iceland                                              14.61           81.0   \n",
       "Ireland                                              15.19           70.0   \n",
       "Israel                                               14.48           68.0   \n",
       "Italy                                                14.98           75.0   \n",
       "Japan                                                14.93           53.0   \n",
       "Korea                                                14.63           76.0   \n",
       "Luxembourg                                           15.12           91.0   \n",
       "Mexico                                               13.89           63.0   \n",
       "Netherlands                                          15.44           75.0   \n",
       "New Zealand                                          14.87           77.0   \n",
       "Norway                                               15.56           78.0   \n",
       "OECD - Total                                         14.97           68.0   \n",
       "Poland                                               14.20           55.0   \n",
       "Portugal                                             14.95           58.0   \n",
       "Russia                                               14.97           65.0   \n",
       "Slovak Republic                                      14.99           59.0   \n",
       "Slovenia                                             14.62           52.0   \n",
       "Spain                                                16.06           69.0   \n",
       "Sweden                                               15.11           86.0   \n",
       "Switzerland                                          14.98           49.0   \n",
       "Turkey                                               13.42           88.0   \n",
       "United Kingdom                                       14.83           66.0   \n",
       "United States                                        14.27           68.0   \n",
       "\n",
       "Indicator        Water quality  Years in education  \n",
       "Country                                             \n",
       "Australia                 91.0                19.4  \n",
       "Austria                   94.0                17.0  \n",
       "Belgium                   87.0                18.9  \n",
       "Brazil                    72.0                16.3  \n",
       "Canada                    91.0                17.2  \n",
       "Chile                     73.0                16.5  \n",
       "Czech Republic            85.0                18.1  \n",
       "Denmark                   94.0                19.4  \n",
       "Estonia                   79.0                17.5  \n",
       "Finland                   94.0                19.7  \n",
       "France                    82.0                16.4  \n",
       "Germany                   95.0                18.2  \n",
       "Greece                    69.0                18.6  \n",
       "Hungary                   77.0                17.6  \n",
       "Iceland                   97.0                19.8  \n",
       "Ireland                   80.0                17.6  \n",
       "Israel                    68.0                15.8  \n",
       "Italy                     71.0                16.8  \n",
       "Japan                     85.0                16.3  \n",
       "Korea                     78.0                17.5  \n",
       "Luxembourg                86.0                15.1  \n",
       "Mexico                    67.0                14.4  \n",
       "Netherlands               92.0                18.7  \n",
       "New Zealand               89.0                18.1  \n",
       "Norway                    94.0                17.9  \n",
       "OECD - Total              81.0                17.7  \n",
       "Poland                    79.0                18.4  \n",
       "Portugal                  86.0                17.6  \n",
       "Russia                    56.0                16.0  \n",
       "Slovak Republic           81.0                16.3  \n",
       "Slovenia                  88.0                18.4  \n",
       "Spain                     71.0                17.6  \n",
       "Sweden                    95.0                19.3  \n",
       "Switzerland               96.0                17.3  \n",
       "Turkey                    62.0                16.4  \n",
       "United Kingdom            88.0                16.4  \n",
       "United States             85.0                17.2  \n",
       "\n",
       "[37 rows x 24 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "life_sat_pivoted = life_sat_total.pivot(index=\"Country\", columns=\"Indicator\", values=\"Value\")\n",
    "life_sat_pivoted"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6bb04a1c",
   "metadata": {},
   "source": [
    "## GDP per capita\n",
    "\n",
    "*Gross domestic product* (GDP) per capita is an economic metric that breaks down a country's economic output per person. Economists use GDP per capita to determine how prosperous countries are based on their economic growth.\n",
    "\n",
    "GDP per capita is calculated by dividing the GDP of a nation by its population. Countries with the higher GDP per capita tend to be those that are industrial, developed countries.\n",
    "\n",
    "Thus, **GDP per capita measures the economic output of a nation per person.**\n",
    "\n",
    "---\n",
    "\n",
    "The Dataset obtained from the IMF's website at: http://goo.gl/j1MSKe\n",
    "\n",
    "### Data description\n",
    "```\n",
    "Int64Index: 190 entries, 0 to 189\n",
    "Data columns (total 7 columns):\n",
    "Country                          190 non-null object\n",
    "Subject Descriptor               189 non-null object\n",
    "Units                            189 non-null object\n",
    "Scale                            189 non-null object\n",
    "Country/Series-specific Notes    188 non-null object\n",
    "2015                             187 non-null float64\n",
    "Estimates Start After            188 non-null float64\n",
    "dtypes: float64(2), object(5)\n",
    "memory usage: 11.9+ KB\n",
    "```\n",
    "\n",
    "### Example using Python Pandas\n",
    "\n",
    "```\n",
    ">>> gdp_per_capita = pd.read_csv(\n",
    "...     datapath+\"gdp_per_capita.csv\", thousands=',', delimiter='\\t',\n",
    "...     encoding='latin1', na_values=\"n/a\", index_col=\"Country\")\n",
    "...\n",
    ">>> gdp_per_capita.rename(columns={\"2015\": \"GDP per capita\"}, inplace=True)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "fc31575a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>Subject Descriptor</th>\n",
       "      <th>Units</th>\n",
       "      <th>Scale</th>\n",
       "      <th>Country/Series-specific Notes</th>\n",
       "      <th>2015</th>\n",
       "      <th>Estimates Start After</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>599.994</td>\n",
       "      <td>2013.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Albania</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>3995.383</td>\n",
       "      <td>2010.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Algeria</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>4318.135</td>\n",
       "      <td>2014.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Angola</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>4100.315</td>\n",
       "      <td>2014.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Antigua and Barbuda</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>14414.302</td>\n",
       "      <td>2011.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185</th>\n",
       "      <td>Vietnam</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>2088.344</td>\n",
       "      <td>2012.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>186</th>\n",
       "      <td>Yemen</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>1302.940</td>\n",
       "      <td>2008.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>187</th>\n",
       "      <td>Zambia</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>1350.151</td>\n",
       "      <td>2010.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>Zimbabwe</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>1064.350</td>\n",
       "      <td>2012.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>International Monetary Fund, World Economic Ou...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>190 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               Country  \\\n",
       "0                                          Afghanistan   \n",
       "1                                              Albania   \n",
       "2                                              Algeria   \n",
       "3                                               Angola   \n",
       "4                                  Antigua and Barbuda   \n",
       "..                                                 ...   \n",
       "185                                            Vietnam   \n",
       "186                                              Yemen   \n",
       "187                                             Zambia   \n",
       "188                                           Zimbabwe   \n",
       "189  International Monetary Fund, World Economic Ou...   \n",
       "\n",
       "                                    Subject Descriptor         Units  Scale  \\\n",
       "0    Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "1    Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "2    Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "3    Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "4    Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "..                                                 ...           ...    ...   \n",
       "185  Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "186  Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "187  Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "188  Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "189                                                NaN           NaN    NaN   \n",
       "\n",
       "                         Country/Series-specific Notes       2015  \\\n",
       "0    See notes for:  Gross domestic product, curren...    599.994   \n",
       "1    See notes for:  Gross domestic product, curren...   3995.383   \n",
       "2    See notes for:  Gross domestic product, curren...   4318.135   \n",
       "3    See notes for:  Gross domestic product, curren...   4100.315   \n",
       "4    See notes for:  Gross domestic product, curren...  14414.302   \n",
       "..                                                 ...        ...   \n",
       "185  See notes for:  Gross domestic product, curren...   2088.344   \n",
       "186  See notes for:  Gross domestic product, curren...   1302.940   \n",
       "187  See notes for:  Gross domestic product, curren...   1350.151   \n",
       "188  See notes for:  Gross domestic product, curren...   1064.350   \n",
       "189                                                NaN        NaN   \n",
       "\n",
       "     Estimates Start After  \n",
       "0                   2013.0  \n",
       "1                   2010.0  \n",
       "2                   2014.0  \n",
       "3                   2014.0  \n",
       "4                   2011.0  \n",
       "..                     ...  \n",
       "185                 2012.0  \n",
       "186                 2008.0  \n",
       "187                 2010.0  \n",
       "188                 2012.0  \n",
       "189                    NaN  \n",
       "\n",
       "[190 rows x 7 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url2 = \"https://raw.githubusercontent.com/machine-learning-course-uac/1-ml-landscape/main/gdp_per_capita.csv\"\n",
    "gdp_per_capita = pd.read_csv(url2,thousands=',',delimiter='\\t', encoding='latin1', na_values=\"n/a\")\n",
    "gdp_per_capita"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b355820d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>Subject Descriptor</th>\n",
       "      <th>Units</th>\n",
       "      <th>Scale</th>\n",
       "      <th>Country/Series-specific Notes</th>\n",
       "      <th>GDP</th>\n",
       "      <th>Estimates Start After</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>599.994</td>\n",
       "      <td>2013.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Albania</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>3995.383</td>\n",
       "      <td>2010.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Algeria</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>4318.135</td>\n",
       "      <td>2014.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Angola</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>4100.315</td>\n",
       "      <td>2014.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Antigua and Barbuda</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>14414.302</td>\n",
       "      <td>2011.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185</th>\n",
       "      <td>Vietnam</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>2088.344</td>\n",
       "      <td>2012.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>186</th>\n",
       "      <td>Yemen</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>1302.940</td>\n",
       "      <td>2008.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>187</th>\n",
       "      <td>Zambia</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>1350.151</td>\n",
       "      <td>2010.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>Zimbabwe</td>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>1064.350</td>\n",
       "      <td>2012.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>International Monetary Fund, World Economic Ou...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>190 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               Country  \\\n",
       "0                                          Afghanistan   \n",
       "1                                              Albania   \n",
       "2                                              Algeria   \n",
       "3                                               Angola   \n",
       "4                                  Antigua and Barbuda   \n",
       "..                                                 ...   \n",
       "185                                            Vietnam   \n",
       "186                                              Yemen   \n",
       "187                                             Zambia   \n",
       "188                                           Zimbabwe   \n",
       "189  International Monetary Fund, World Economic Ou...   \n",
       "\n",
       "                                    Subject Descriptor         Units  Scale  \\\n",
       "0    Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "1    Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "2    Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "3    Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "4    Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "..                                                 ...           ...    ...   \n",
       "185  Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "186  Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "187  Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "188  Gross domestic product per capita, current prices  U.S. dollars  Units   \n",
       "189                                                NaN           NaN    NaN   \n",
       "\n",
       "                         Country/Series-specific Notes        GDP  \\\n",
       "0    See notes for:  Gross domestic product, curren...    599.994   \n",
       "1    See notes for:  Gross domestic product, curren...   3995.383   \n",
       "2    See notes for:  Gross domestic product, curren...   4318.135   \n",
       "3    See notes for:  Gross domestic product, curren...   4100.315   \n",
       "4    See notes for:  Gross domestic product, curren...  14414.302   \n",
       "..                                                 ...        ...   \n",
       "185  See notes for:  Gross domestic product, curren...   2088.344   \n",
       "186  See notes for:  Gross domestic product, curren...   1302.940   \n",
       "187  See notes for:  Gross domestic product, curren...   1350.151   \n",
       "188  See notes for:  Gross domestic product, curren...   1064.350   \n",
       "189                                                NaN        NaN   \n",
       "\n",
       "     Estimates Start After  \n",
       "0                   2013.0  \n",
       "1                   2010.0  \n",
       "2                   2014.0  \n",
       "3                   2014.0  \n",
       "4                   2011.0  \n",
       "..                     ...  \n",
       "185                 2012.0  \n",
       "186                 2008.0  \n",
       "187                 2010.0  \n",
       "188                 2012.0  \n",
       "189                    NaN  \n",
       "\n",
       "[190 rows x 7 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdp_per_capita.rename(columns={\"2015\": \"GDP\"}, inplace=True)\n",
    "gdp_per_capita"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "44bce56b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Subject Descriptor</th>\n",
       "      <th>Units</th>\n",
       "      <th>Scale</th>\n",
       "      <th>Country/Series-specific Notes</th>\n",
       "      <th>GDP</th>\n",
       "      <th>Estimates Start After</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Country</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Afghanistan</th>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>599.994</td>\n",
       "      <td>2013.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Albania</th>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>3995.383</td>\n",
       "      <td>2010.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Algeria</th>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>4318.135</td>\n",
       "      <td>2014.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Angola</th>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>4100.315</td>\n",
       "      <td>2014.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Antigua and Barbuda</th>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>14414.302</td>\n",
       "      <td>2011.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Vietnam</th>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>2088.344</td>\n",
       "      <td>2012.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Yemen</th>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>1302.940</td>\n",
       "      <td>2008.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zambia</th>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>1350.151</td>\n",
       "      <td>2010.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zimbabwe</th>\n",
       "      <td>Gross domestic product per capita, current prices</td>\n",
       "      <td>U.S. dollars</td>\n",
       "      <td>Units</td>\n",
       "      <td>See notes for:  Gross domestic product, curren...</td>\n",
       "      <td>1064.350</td>\n",
       "      <td>2012.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>International Monetary Fund, World Economic Outlook Database, April 2016</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>190 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                                   Subject Descriptor  \\\n",
       "Country                                                                                                 \n",
       "Afghanistan                                         Gross domestic product per capita, current prices   \n",
       "Albania                                             Gross domestic product per capita, current prices   \n",
       "Algeria                                             Gross domestic product per capita, current prices   \n",
       "Angola                                              Gross domestic product per capita, current prices   \n",
       "Antigua and Barbuda                                 Gross domestic product per capita, current prices   \n",
       "...                                                                                               ...   \n",
       "Vietnam                                             Gross domestic product per capita, current prices   \n",
       "Yemen                                               Gross domestic product per capita, current prices   \n",
       "Zambia                                              Gross domestic product per capita, current prices   \n",
       "Zimbabwe                                            Gross domestic product per capita, current prices   \n",
       "International Monetary Fund, World Economic Out...                                                NaN   \n",
       "\n",
       "                                                           Units  Scale  \\\n",
       "Country                                                                   \n",
       "Afghanistan                                         U.S. dollars  Units   \n",
       "Albania                                             U.S. dollars  Units   \n",
       "Algeria                                             U.S. dollars  Units   \n",
       "Angola                                              U.S. dollars  Units   \n",
       "Antigua and Barbuda                                 U.S. dollars  Units   \n",
       "...                                                          ...    ...   \n",
       "Vietnam                                             U.S. dollars  Units   \n",
       "Yemen                                               U.S. dollars  Units   \n",
       "Zambia                                              U.S. dollars  Units   \n",
       "Zimbabwe                                            U.S. dollars  Units   \n",
       "International Monetary Fund, World Economic Out...           NaN    NaN   \n",
       "\n",
       "                                                                        Country/Series-specific Notes  \\\n",
       "Country                                                                                                 \n",
       "Afghanistan                                         See notes for:  Gross domestic product, curren...   \n",
       "Albania                                             See notes for:  Gross domestic product, curren...   \n",
       "Algeria                                             See notes for:  Gross domestic product, curren...   \n",
       "Angola                                              See notes for:  Gross domestic product, curren...   \n",
       "Antigua and Barbuda                                 See notes for:  Gross domestic product, curren...   \n",
       "...                                                                                               ...   \n",
       "Vietnam                                             See notes for:  Gross domestic product, curren...   \n",
       "Yemen                                               See notes for:  Gross domestic product, curren...   \n",
       "Zambia                                              See notes for:  Gross domestic product, curren...   \n",
       "Zimbabwe                                            See notes for:  Gross domestic product, curren...   \n",
       "International Monetary Fund, World Economic Out...                                                NaN   \n",
       "\n",
       "                                                          GDP  \\\n",
       "Country                                                         \n",
       "Afghanistan                                           599.994   \n",
       "Albania                                              3995.383   \n",
       "Algeria                                              4318.135   \n",
       "Angola                                               4100.315   \n",
       "Antigua and Barbuda                                 14414.302   \n",
       "...                                                       ...   \n",
       "Vietnam                                              2088.344   \n",
       "Yemen                                                1302.940   \n",
       "Zambia                                               1350.151   \n",
       "Zimbabwe                                             1064.350   \n",
       "International Monetary Fund, World Economic Out...        NaN   \n",
       "\n",
       "                                                    Estimates Start After  \n",
       "Country                                                                    \n",
       "Afghanistan                                                        2013.0  \n",
       "Albania                                                            2010.0  \n",
       "Algeria                                                            2014.0  \n",
       "Angola                                                             2014.0  \n",
       "Antigua and Barbuda                                                2011.0  \n",
       "...                                                                   ...  \n",
       "Vietnam                                                            2012.0  \n",
       "Yemen                                                              2008.0  \n",
       "Zambia                                                             2010.0  \n",
       "Zimbabwe                                                           2012.0  \n",
       "International Monetary Fund, World Economic Out...                    NaN  \n",
       "\n",
       "[190 rows x 6 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gdp_per_capita.set_index(\"Country\", inplace=True)\n",
    "gdp_per_capita"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d334c46b",
   "metadata": {},
   "source": [
    "# Making all the process in a function "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "a0cb5245",
   "metadata": {},
   "outputs": [],
   "source": [
    "def CountryStats(oecd, gdp):\n",
    "    # YOUR CODE HERE\n",
    "    return country_stats[[\"GDP\", 'Life satisfaction']].iloc[keep_indices]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "37cd9901",
   "metadata": {},
   "outputs": [],
   "source": [
    "import mluac as ml\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "df9ca7f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GDP per capita</th>\n",
       "      <th>Life satisfaction</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Country</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Russia</th>\n",
       "      <td>9054.914</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Turkey</th>\n",
       "      <td>9437.372</td>\n",
       "      <td>5.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hungary</th>\n",
       "      <td>12239.894</td>\n",
       "      <td>4.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Poland</th>\n",
       "      <td>12495.334</td>\n",
       "      <td>5.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Slovak Republic</th>\n",
       "      <td>15991.736</td>\n",
       "      <td>6.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Estonia</th>\n",
       "      <td>17288.083</td>\n",
       "      <td>5.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Greece</th>\n",
       "      <td>18064.288</td>\n",
       "      <td>4.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Portugal</th>\n",
       "      <td>19121.592</td>\n",
       "      <td>5.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Slovenia</th>\n",
       "      <td>20732.482</td>\n",
       "      <td>5.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spain</th>\n",
       "      <td>25864.721</td>\n",
       "      <td>6.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Korea</th>\n",
       "      <td>27195.197</td>\n",
       "      <td>5.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Italy</th>\n",
       "      <td>29866.581</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Japan</th>\n",
       "      <td>32485.545</td>\n",
       "      <td>5.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Israel</th>\n",
       "      <td>35343.336</td>\n",
       "      <td>7.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Zealand</th>\n",
       "      <td>37044.891</td>\n",
       "      <td>7.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>France</th>\n",
       "      <td>37675.006</td>\n",
       "      <td>6.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Belgium</th>\n",
       "      <td>40106.632</td>\n",
       "      <td>6.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Germany</th>\n",
       "      <td>40996.511</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Finland</th>\n",
       "      <td>41973.988</td>\n",
       "      <td>7.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Canada</th>\n",
       "      <td>43331.961</td>\n",
       "      <td>7.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Netherlands</th>\n",
       "      <td>43603.115</td>\n",
       "      <td>7.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austria</th>\n",
       "      <td>43724.031</td>\n",
       "      <td>6.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United Kingdom</th>\n",
       "      <td>43770.688</td>\n",
       "      <td>6.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sweden</th>\n",
       "      <td>49866.266</td>\n",
       "      <td>7.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iceland</th>\n",
       "      <td>50854.583</td>\n",
       "      <td>7.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Australia</th>\n",
       "      <td>50961.865</td>\n",
       "      <td>7.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ireland</th>\n",
       "      <td>51350.744</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Denmark</th>\n",
       "      <td>52114.165</td>\n",
       "      <td>7.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United States</th>\n",
       "      <td>55805.204</td>\n",
       "      <td>7.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 GDP per capita  Life satisfaction\n",
       "Country                                           \n",
       "Russia                 9054.914                6.0\n",
       "Turkey                 9437.372                5.6\n",
       "Hungary               12239.894                4.9\n",
       "Poland                12495.334                5.8\n",
       "Slovak Republic       15991.736                6.1\n",
       "Estonia               17288.083                5.6\n",
       "Greece                18064.288                4.8\n",
       "Portugal              19121.592                5.1\n",
       "Slovenia              20732.482                5.7\n",
       "Spain                 25864.721                6.5\n",
       "Korea                 27195.197                5.8\n",
       "Italy                 29866.581                6.0\n",
       "Japan                 32485.545                5.9\n",
       "Israel                35343.336                7.4\n",
       "New Zealand           37044.891                7.3\n",
       "France                37675.006                6.5\n",
       "Belgium               40106.632                6.9\n",
       "Germany               40996.511                7.0\n",
       "Finland               41973.988                7.4\n",
       "Canada                43331.961                7.3\n",
       "Netherlands           43603.115                7.3\n",
       "Austria               43724.031                6.9\n",
       "United Kingdom        43770.688                6.8\n",
       "Sweden                49866.266                7.2\n",
       "Iceland               50854.583                7.5\n",
       "Australia             50961.865                7.3\n",
       "Ireland               51350.744                7.0\n",
       "Denmark               52114.165                7.5\n",
       "United States         55805.204                7.2"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url2 = \"https://raw.githubusercontent.com/machine-learning-course-uac/1-ml-landscape/main/gdp_per_capita.csv\"\n",
    "gdp_per_capita = pd.read_csv(url2,thousands=',',delimiter='\\t', encoding='latin1', na_values=\"n/a\")\n",
    "url = \"https://raw.githubusercontent.com/machine-learning-course-uac/1-ml-landscape/main/oecd_bli_2015.csv\"\n",
    "oecd_bli = pd.read_csv(url, thousands=',')\n",
    "cs = ml.prepare_country_stats(oecd_bli, gdp_per_capita)\n",
    "cs"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3466ca29",
   "metadata": {},
   "source": [
    "## Exploring the data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5bfd30f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "X = np.c_[cs[\"GDP per capita\"]]\n",
    "y = np.c_[cs[\"Life satisfaction\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "51ac6ffc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 9054.914],\n",
       "       [ 9437.372],\n",
       "       [12239.894],\n",
       "       [12495.334],\n",
       "       [15991.736],\n",
       "       [17288.083],\n",
       "       [18064.288],\n",
       "       [19121.592],\n",
       "       [20732.482],\n",
       "       [25864.721],\n",
       "       [27195.197],\n",
       "       [29866.581],\n",
       "       [32485.545],\n",
       "       [35343.336],\n",
       "       [37044.891],\n",
       "       [37675.006],\n",
       "       [40106.632],\n",
       "       [40996.511],\n",
       "       [41973.988],\n",
       "       [43331.961],\n",
       "       [43603.115],\n",
       "       [43724.031],\n",
       "       [43770.688],\n",
       "       [49866.266],\n",
       "       [50854.583],\n",
       "       [50961.865],\n",
       "       [51350.744],\n",
       "       [52114.165],\n",
       "       [55805.204]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "ba85eda2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6. ],\n",
       "       [5.6],\n",
       "       [4.9],\n",
       "       [5.8],\n",
       "       [6.1],\n",
       "       [5.6],\n",
       "       [4.8],\n",
       "       [5.1],\n",
       "       [5.7],\n",
       "       [6.5],\n",
       "       [5.8],\n",
       "       [6. ],\n",
       "       [5.9],\n",
       "       [7.4],\n",
       "       [7.3],\n",
       "       [6.5],\n",
       "       [6.9],\n",
       "       [7. ],\n",
       "       [7.4],\n",
       "       [7.3],\n",
       "       [7.3],\n",
       "       [6.9],\n",
       "       [6.8],\n",
       "       [7.2],\n",
       "       [7.5],\n",
       "       [7.3],\n",
       "       [7. ],\n",
       "       [7.5],\n",
       "       [7.2]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "75460ea4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33504 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(X,y, 'ok', markersize=12, label=\"Data\")\n",
    "plt.xlabel(\"GDP per capita\", fontsize=20)\n",
    "plt.ylabel(\"Life satisfaction\", fontsize=20)\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d4cdb351",
   "metadata": {},
   "source": [
    "# Model of GDP and Life Satisfaction\n",
    "## Fitting and predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "13fabb3b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "# Select a linear model\n",
    "model = LinearRegression()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "86ee41bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-3 {color: black;background-color: white;}#sk-container-id-3 pre{padding: 0;}#sk-container-id-3 div.sk-toggleable {background-color: white;}#sk-container-id-3 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-3 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-3 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-3 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-3 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-3 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-3 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-3 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-3 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-3 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-3 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-3 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-3 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-3 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-3 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-3 div.sk-item {position: relative;z-index: 1;}#sk-container-id-3 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-3 div.sk-item::before, #sk-container-id-3 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-3 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-3 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-3 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-3 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-3 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-3 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-3 div.sk-label-container {text-align: center;}#sk-container-id-3 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-3 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-3\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>LinearRegression()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-3\" type=\"checkbox\" checked><label for=\"sk-estimator-id-3\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">LinearRegression</label><div class=\"sk-toggleable__content\"><pre>LinearRegression()</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "LinearRegression()"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Train the model\n",
    "model.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "25b99bc8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[5.96242338]]\n"
     ]
    }
   ],
   "source": [
    "# Make a prediction for Cyprus\n",
    "X_new = [[22587]]  # Cyprus' GDP per capita\n",
    "print(model.predict(X_new)) # outputs [[ 5.96242338]]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe2c6057",
   "metadata": {},
   "source": [
    "## Extracting data from model\n",
    "\n",
    "The Linear regression model\n",
    "\n",
    "$$f(\\theta)=x_0 +x_1 \\theta_1 +x_2 \\theta_2 + \\cdots$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "5278c68f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.853052800266435"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#theta_0\n",
    "t0 = model.intercept_[0]\n",
    "t0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "7964db8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4.91154459e-05]])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#theta_1\n",
    "t1 =model.coef_\n",
    "t1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "2c494d36",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 42724 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "Xest=np.linspace(0, 60000, 1000)\n",
    "plt.plot(X, t0 + t1*X, \"r\", linewidth=3,label=\"Model\")\n",
    "plt.plot(X,y, 'ok', markersize=12, label=\"Data\")\n",
    "plt.xlabel(\"GDP per capita\", fontsize=20)\n",
    "plt.ylabel(\"Life satisfaction\", fontsize=20)\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
