Data Every Day: COVID-19 健康的な食事データセット

# tldr

Kggleの[COVID-19 Healthy Diet Dataset](https://www.kaggle.com/mariaren/covid19-healthy-diet-dataset)を[Predicting COVID-19 Mortality - Data Every Day #048](https://www.youtube.com/watch?v=LLC8rmmVOjM&list=PLs_CQl4mUvI7Z9HnwoeOS5EUu9gyvekjK&index=48&t=4s)に沿ってやっていきます。

実行環境はGoogle Colaboratorです。

# インポート


```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

import sklearn.preprocessing as sp
from sklearn.model_selection import train_test_split
import sklearn.linear_model as slm

import tensorflow as tf
```

# データのダウンロード

Google Driveをマウントします。


```python
from google.colab import drive
drive.mount('/content/drive')
```

    Mounted at /content/drive


KaggleのAPIクライアントを初期化し、認証します。
認証情報はGoogle Drive内（`/content/drive/My Drive/Colab Notebooks/Kaggle`）に`kaggle.json`として置いてあります。


```python
import os
kaggle_path = "/content/drive/My Drive/Colab Notebooks/Kaggle"
os.environ['KAGGLE_CONFIG_DIR'] = kaggle_path

from kaggle.api.kaggle_api_extended import KaggleApi
api = KaggleApi()
api.authenticate() 
```

Kaggle APIを使ってデータをダウンロードします。


```python
dataset_id = 'mariaren/covid19-healthy-diet-dataset'
dataset = api.dataset_list_files(dataset_id)
file_name = dataset.files[0].name
file_path = os.path.join(api.get_default_download_dir(), file_name)
file_path
```




    '/content/Food_Supply_Quantity_kg_Data.csv'




```python
api.dataset_download_file(dataset_id, file_name, force=True, quiet=False)
```

    100%|██████████| 43.4k/43.4k [00:00<00:00, 22.3MB/s]

    Downloading Food_Supply_Quantity_kg_Data.csv to /content
    


    





    True



# データの読み込み


```python
data = pd.read_csv(file_path)
```


```python
data
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Country</th>
      <th>Alcoholic Beverages</th>
      <th>Animal fats</th>
      <th>Animal Products</th>
      <th>Aquatic Products, Other</th>
      <th>Cereals - Excluding Beer</th>
      <th>Eggs</th>
      <th>Fish, Seafood</th>
      <th>Fruits - Excluding Wine</th>
      <th>Meat</th>
      <th>Milk - Excluding Butter</th>
      <th>Miscellaneous</th>
      <th>Offals</th>
      <th>Oilcrops</th>
      <th>Pulses</th>
      <th>Spices</th>
      <th>Starchy Roots</th>
      <th>Stimulants</th>
      <th>Sugar &amp; Sweeteners</th>
      <th>Sugar Crops</th>
      <th>Treenuts</th>
      <th>Vegetable Oils</th>
      <th>Vegetables</th>
      <th>Vegetal Products</th>
      <th>Obesity</th>
      <th>Undernourished</th>
      <th>Confirmed</th>
      <th>Deaths</th>
      <th>Recovered</th>
      <th>Active</th>
      <th>Population</th>
      <th>Unit (all except Population)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Afghanistan</td>
      <td>0.0014</td>
      <td>0.1973</td>
      <td>9.4341</td>
      <td>0.0000</td>
      <td>24.8097</td>
      <td>0.2099</td>
      <td>0.0350</td>
      <td>5.3495</td>
      <td>1.2020</td>
      <td>7.5828</td>
      <td>0.0728</td>
      <td>0.2057</td>
      <td>0.0700</td>
      <td>0.2953</td>
      <td>0.0574</td>
      <td>0.8802</td>
      <td>0.3078</td>
      <td>1.3489</td>
      <td>0.000</td>
      <td>0.0770</td>
      <td>0.5345</td>
      <td>6.7642</td>
      <td>40.5645</td>
      <td>4.5</td>
      <td>29.8</td>
      <td>0.125149</td>
      <td>0.005058</td>
      <td>0.098263</td>
      <td>0.021827</td>
      <td>38928000.0</td>
      <td>%</td>
    </tr>
    <tr>
      <th>1</th>
      <td>Albania</td>
      <td>1.6719</td>
      <td>0.1357</td>
      <td>18.7684</td>
      <td>0.0000</td>
      <td>5.7817</td>
      <td>0.5815</td>
      <td>0.2126</td>
      <td>6.7861</td>
      <td>1.8845</td>
      <td>15.7213</td>
      <td>0.1123</td>
      <td>0.2324</td>
      <td>0.9377</td>
      <td>0.2380</td>
      <td>0.0008</td>
      <td>1.8096</td>
      <td>0.1055</td>
      <td>1.5367</td>
      <td>0.000</td>
      <td>0.1515</td>
      <td>0.3261</td>
      <td>11.7753</td>
      <td>31.2304</td>
      <td>22.3</td>
      <td>6.2</td>
      <td>1.733298</td>
      <td>0.035800</td>
      <td>0.874560</td>
      <td>0.822939</td>
      <td>2838000.0</td>
      <td>%</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Algeria</td>
      <td>0.2711</td>
      <td>0.0282</td>
      <td>9.6334</td>
      <td>0.0000</td>
      <td>13.6816</td>
      <td>0.5277</td>
      <td>0.2416</td>
      <td>6.3801</td>
      <td>1.1305</td>
      <td>7.6189</td>
      <td>0.1671</td>
      <td>0.0870</td>
      <td>0.3493</td>
      <td>0.4783</td>
      <td>0.0557</td>
      <td>4.1340</td>
      <td>0.2216</td>
      <td>1.8342</td>
      <td>0.000</td>
      <td>0.1152</td>
      <td>1.0310</td>
      <td>11.6484</td>
      <td>40.3651</td>
      <td>26.6</td>
      <td>3.9</td>
      <td>0.208754</td>
      <td>0.005882</td>
      <td>0.137268</td>
      <td>0.065604</td>
      <td>44357000.0</td>
      <td>%</td>
    </tr>
    <tr>
      <th>3</th>
      <td>Angola</td>
      <td>5.8087</td>
      <td>0.0560</td>
      <td>4.9278</td>
      <td>0.0000</td>
      <td>9.1085</td>
      <td>0.0587</td>
      <td>1.7707</td>
      <td>6.0005</td>
      <td>2.0571</td>
      <td>0.8311</td>
      <td>0.1165</td>
      <td>0.1550</td>
      <td>0.4186</td>
      <td>0.6507</td>
      <td>0.0009</td>
      <td>18.1102</td>
      <td>0.0508</td>
      <td>1.8495</td>
      <td>0.000</td>
      <td>0.0061</td>
      <td>0.6463</td>
      <td>2.3041</td>
      <td>45.0722</td>
      <td>6.8</td>
      <td>25</td>
      <td>0.050049</td>
      <td>0.001144</td>
      <td>0.027440</td>
      <td>0.021465</td>
      <td>32522000.0</td>
      <td>%</td>
    </tr>
    <tr>
      <th>4</th>
      <td>Antigua and Barbuda</td>
      <td>3.5764</td>
      <td>0.0087</td>
      <td>16.6613</td>
      <td>0.0000</td>
      <td>5.9960</td>
      <td>0.2274</td>
      <td>4.1489</td>
      <td>10.7451</td>
      <td>5.6888</td>
      <td>6.3663</td>
      <td>0.7139</td>
      <td>0.2219</td>
      <td>0.2172</td>
      <td>0.1840</td>
      <td>0.1524</td>
      <td>1.4522</td>
      <td>0.1564</td>
      <td>3.8749</td>
      <td>0.000</td>
      <td>0.0253</td>
      <td>0.8102</td>
      <td>5.4495</td>
      <td>33.3233</td>
      <td>19.1</td>
      <td>NaN</td>
      <td>0.151020</td>
      <td>0.005102</td>
      <td>0.140816</td>
      <td>0.005102</td>
      <td>98000.0</td>
      <td>%</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>165</th>
      <td>Venezuela (Bolivarian Republic of)</td>
      <td>2.5952</td>
      <td>0.0403</td>
      <td>14.7565</td>
      <td>0.0000</td>
      <td>12.9253</td>
      <td>0.3389</td>
      <td>0.9456</td>
      <td>7.6460</td>
      <td>3.8328</td>
      <td>9.3920</td>
      <td>0.0702</td>
      <td>0.2078</td>
      <td>0.0281</td>
      <td>0.3342</td>
      <td>0.0009</td>
      <td>2.5643</td>
      <td>0.1479</td>
      <td>3.4106</td>
      <td>0.000</td>
      <td>0.0009</td>
      <td>1.3734</td>
      <td>4.1474</td>
      <td>35.2416</td>
      <td>25.2</td>
      <td>21.2</td>
      <td>0.377466</td>
      <td>0.003351</td>
      <td>0.359703</td>
      <td>0.014411</td>
      <td>28645000.0</td>
      <td>%</td>
    </tr>
    <tr>
      <th>166</th>
      <td>Vietnam</td>
      <td>1.4591</td>
      <td>0.1640</td>
      <td>8.5765</td>
      <td>0.0042</td>
      <td>16.8740</td>
      <td>0.3077</td>
      <td>2.6392</td>
      <td>5.9029</td>
      <td>4.4382</td>
      <td>0.6069</td>
      <td>0.0126</td>
      <td>0.4149</td>
      <td>0.8410</td>
      <td>0.2032</td>
      <td>0.2074</td>
      <td>1.0596</td>
      <td>0.2880</td>
      <td>1.2846</td>
      <td>0.815</td>
      <td>0.3070</td>
      <td>0.2201</td>
      <td>11.9508</td>
      <td>41.4232</td>
      <td>2.1</td>
      <td>9.3</td>
      <td>0.001457</td>
      <td>0.000036</td>
      <td>0.001295</td>
      <td>0.000126</td>
      <td>96209000.0</td>
      <td>%</td>
    </tr>
    <tr>
      <th>167</th>
      <td>Yemen</td>
      <td>0.0364</td>
      <td>0.0446</td>
      <td>5.7874</td>
      <td>0.0000</td>
      <td>27.2077</td>
      <td>0.2579</td>
      <td>0.5240</td>
      <td>5.1344</td>
      <td>2.7871</td>
      <td>1.8911</td>
      <td>0.2033</td>
      <td>0.2827</td>
      <td>0.0893</td>
      <td>0.8645</td>
      <td>0.0347</td>
      <td>1.0794</td>
      <td>0.2199</td>
      <td>5.0468</td>
      <td>0.000</td>
      <td>0.0017</td>
      <td>1.0811</td>
      <td>3.2135</td>
      <td>44.2126</td>
      <td>14.1</td>
      <td>38.9</td>
      <td>0.006987</td>
      <td>0.002032</td>
      <td>0.004640</td>
      <td>0.000315</td>
      <td>29826000.0</td>
      <td>%</td>
    </tr>
    <tr>
      <th>168</th>
      <td>Zambia</td>
      <td>5.7360</td>
      <td>0.0829</td>
      <td>6.0197</td>
      <td>0.0000</td>
      <td>21.1938</td>
      <td>0.3399</td>
      <td>1.6924</td>
      <td>1.0183</td>
      <td>1.8427</td>
      <td>1.7570</td>
      <td>0.2149</td>
      <td>0.3048</td>
      <td>1.8736</td>
      <td>0.1756</td>
      <td>0.0478</td>
      <td>7.9649</td>
      <td>0.0618</td>
      <td>1.5632</td>
      <td>0.000</td>
      <td>0.0014</td>
      <td>0.6657</td>
      <td>3.4649</td>
      <td>43.9789</td>
      <td>6.5</td>
      <td>46.7</td>
      <td>0.099663</td>
      <td>0.001996</td>
      <td>0.094696</td>
      <td>0.002970</td>
      <td>18384000.0</td>
      <td>%</td>
    </tr>
    <tr>
      <th>169</th>
      <td>Zimbabwe</td>
      <td>4.0552</td>
      <td>0.0755</td>
      <td>8.1489</td>
      <td>0.0000</td>
      <td>22.6240</td>
      <td>0.2678</td>
      <td>0.5518</td>
      <td>2.2000</td>
      <td>2.6142</td>
      <td>4.4310</td>
      <td>0.2012</td>
      <td>0.2086</td>
      <td>0.4498</td>
      <td>0.4261</td>
      <td>0.0252</td>
      <td>2.9870</td>
      <td>0.1494</td>
      <td>4.6485</td>
      <td>0.000</td>
      <td>0.0518</td>
      <td>1.7103</td>
      <td>2.3213</td>
      <td>41.8526</td>
      <td>12.3</td>
      <td>51.3</td>
      <td>0.076418</td>
      <td>0.002079</td>
      <td>0.064280</td>
      <td>0.010059</td>
      <td>14863000.0</td>
      <td>%</td>
    </tr>
  </tbody>
</table>
<p>170 rows × 32 columns</p>
</div>



# 下準備


```python
data.info()
```

    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 170 entries, 0 to 169
    Data columns (total 32 columns):
     #   Column                        Non-Null Count  Dtype  
    ---  ------                        --------------  -----  
     0   Country                       170 non-null    object 
     1   Alcoholic Beverages           170 non-null    float64
     2   Animal fats                   170 non-null    float64
     3   Animal Products               170 non-null    float64
     4   Aquatic Products, Other       170 non-null    float64
     5   Cereals - Excluding Beer      170 non-null    float64
     6   Eggs                          170 non-null    float64
     7   Fish, Seafood                 170 non-null    float64
     8   Fruits - Excluding Wine       170 non-null    float64
     9   Meat                          170 non-null    float64
     10  Milk - Excluding Butter       170 non-null    float64
     11  Miscellaneous                 170 non-null    float64
     12  Offals                        170 non-null    float64
     13  Oilcrops                      170 non-null    float64
     14  Pulses                        170 non-null    float64
     15  Spices                        170 non-null    float64
     16  Starchy Roots                 170 non-null    float64
     17  Stimulants                    170 non-null    float64
     18  Sugar & Sweeteners            170 non-null    float64
     19  Sugar Crops                   170 non-null    float64
     20  Treenuts                      170 non-null    float64
     21  Vegetable Oils                170 non-null    float64
     22  Vegetables                    170 non-null    float64
     23  Vegetal Products              170 non-null    float64
     24  Obesity                       167 non-null    float64
     25  Undernourished                163 non-null    object 
     26  Confirmed                     164 non-null    float64
     27  Deaths                        164 non-null    float64
     28  Recovered                     164 non-null    float64
     29  Active                        162 non-null    float64
     30  Population                    170 non-null    float64
     31  Unit (all except Population)  170 non-null    object 
    dtypes: float64(29), object(3)
    memory usage: 42.6+ KB



```python
data.isna().sum()
```




    Country                         0
    Alcoholic Beverages             0
    Animal fats                     0
    Animal Products                 0
    Aquatic Products, Other         0
    Cereals - Excluding Beer        0
    Eggs                            0
    Fish, Seafood                   0
    Fruits - Excluding Wine         0
    Meat                            0
    Milk - Excluding Butter         0
    Miscellaneous                   0
    Offals                          0
    Oilcrops                        0
    Pulses                          0
    Spices                          0
    Starchy Roots                   0
    Stimulants                      0
    Sugar & Sweeteners              0
    Sugar Crops                     0
    Treenuts                        0
    Vegetable Oils                  0
    Vegetables                      0
    Vegetal Products                0
    Obesity                         3
    Undernourished                  7
    Confirmed                       6
    Deaths                          6
    Recovered                       6
    Active                          8
    Population                      0
    Unit (all except Population)    0
    dtype: int64




```python
data = data.drop('Unit (all except Population)', axis=1)
```


```python
for column in data.columns:
    if data.dtypes[column] != 'object':
        data[column] = data[column].fillna(data[column].mean())
```


```python
data.isna().sum()
```




    Country                     0
    Alcoholic Beverages         0
    Animal fats                 0
    Animal Products             0
    Aquatic Products, Other     0
    Cereals - Excluding Beer    0
    Eggs                        0
    Fish, Seafood               0
    Fruits - Excluding Wine     0
    Meat                        0
    Milk - Excluding Butter     0
    Miscellaneous               0
    Offals                      0
    Oilcrops                    0
    Pulses                      0
    Spices                      0
    Starchy Roots               0
    Stimulants                  0
    Sugar & Sweeteners          0
    Sugar Crops                 0
    Treenuts                    0
    Vegetable Oils              0
    Vegetables                  0
    Vegetal Products            0
    Obesity                     0
    Undernourished              7
    Confirmed                   0
    Deaths                      0
    Recovered                   0
    Active                      0
    Population                  0
    dtype: int64




```python
undernourished_numeric = data.loc[data['Undernourished'] != '<2.5', 'Undernourished'].astype(np.float)
undernourished_numeric
```




    0      29.8
    1       6.2
    2       3.9
    3      25.0
    4       NaN
           ... 
    165    21.2
    166     9.3
    167    38.9
    168    46.7
    169    51.3
    Name: Undernourished, Length: 126, dtype: float64




```python
undernourished_numeric = undernourished_numeric.fillna(undernourished_numeric.mean())
undernourished_numeric = pd.qcut(undernourished_numeric, q=3, labels=[1, 2, 3])
undernourished_numeric
```




    0      3
    1      1
    2      1
    3      3
    4      2
          ..
    165    3
    166    2
    167    3
    168    3
    169    3
    Name: Undernourished, Length: 126, dtype: category
    Categories (3, int64): [1 < 2 < 3]




```python
data.loc[undernourished_numeric.index, 'Undernourished'] = undernourished_numeric
```


```python
data['Undernourished'] = data['Undernourished'].apply(lambda x: 0 if x == '<2.5' else x)
```


```python
data['Undernourished'].value_counts()
```




    0    44
    3    42
    2    42
    1    42
    Name: Undernourished, dtype: int64




```python
data
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Country</th>
      <th>Alcoholic Beverages</th>
      <th>Animal fats</th>
      <th>Animal Products</th>
      <th>Aquatic Products, Other</th>
      <th>Cereals - Excluding Beer</th>
      <th>Eggs</th>
      <th>Fish, Seafood</th>
      <th>Fruits - Excluding Wine</th>
      <th>Meat</th>
      <th>Milk - Excluding Butter</th>
      <th>Miscellaneous</th>
      <th>Offals</th>
      <th>Oilcrops</th>
      <th>Pulses</th>
      <th>Spices</th>
      <th>Starchy Roots</th>
      <th>Stimulants</th>
      <th>Sugar &amp; Sweeteners</th>
      <th>Sugar Crops</th>
      <th>Treenuts</th>
      <th>Vegetable Oils</th>
      <th>Vegetables</th>
      <th>Vegetal Products</th>
      <th>Obesity</th>
      <th>Undernourished</th>
      <th>Confirmed</th>
      <th>Deaths</th>
      <th>Recovered</th>
      <th>Active</th>
      <th>Population</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Afghanistan</td>
      <td>0.0014</td>
      <td>0.1973</td>
      <td>9.4341</td>
      <td>0.0000</td>
      <td>24.8097</td>
      <td>0.2099</td>
      <td>0.0350</td>
      <td>5.3495</td>
      <td>1.2020</td>
      <td>7.5828</td>
      <td>0.0728</td>
      <td>0.2057</td>
      <td>0.0700</td>
      <td>0.2953</td>
      <td>0.0574</td>
      <td>0.8802</td>
      <td>0.3078</td>
      <td>1.3489</td>
      <td>0.000</td>
      <td>0.0770</td>
      <td>0.5345</td>
      <td>6.7642</td>
      <td>40.5645</td>
      <td>4.5</td>
      <td>3</td>
      <td>0.125149</td>
      <td>0.005058</td>
      <td>0.098263</td>
      <td>0.021827</td>
      <td>38928000.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>Albania</td>
      <td>1.6719</td>
      <td>0.1357</td>
      <td>18.7684</td>
      <td>0.0000</td>
      <td>5.7817</td>
      <td>0.5815</td>
      <td>0.2126</td>
      <td>6.7861</td>
      <td>1.8845</td>
      <td>15.7213</td>
      <td>0.1123</td>
      <td>0.2324</td>
      <td>0.9377</td>
      <td>0.2380</td>
      <td>0.0008</td>
      <td>1.8096</td>
      <td>0.1055</td>
      <td>1.5367</td>
      <td>0.000</td>
      <td>0.1515</td>
      <td>0.3261</td>
      <td>11.7753</td>
      <td>31.2304</td>
      <td>22.3</td>
      <td>1</td>
      <td>1.733298</td>
      <td>0.035800</td>
      <td>0.874560</td>
      <td>0.822939</td>
      <td>2838000.0</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Algeria</td>
      <td>0.2711</td>
      <td>0.0282</td>
      <td>9.6334</td>
      <td>0.0000</td>
      <td>13.6816</td>
      <td>0.5277</td>
      <td>0.2416</td>
      <td>6.3801</td>
      <td>1.1305</td>
      <td>7.6189</td>
      <td>0.1671</td>
      <td>0.0870</td>
      <td>0.3493</td>
      <td>0.4783</td>
      <td>0.0557</td>
      <td>4.1340</td>
      <td>0.2216</td>
      <td>1.8342</td>
      <td>0.000</td>
      <td>0.1152</td>
      <td>1.0310</td>
      <td>11.6484</td>
      <td>40.3651</td>
      <td>26.6</td>
      <td>1</td>
      <td>0.208754</td>
      <td>0.005882</td>
      <td>0.137268</td>
      <td>0.065604</td>
      <td>44357000.0</td>
    </tr>
    <tr>
      <th>3</th>
      <td>Angola</td>
      <td>5.8087</td>
      <td>0.0560</td>
      <td>4.9278</td>
      <td>0.0000</td>
      <td>9.1085</td>
      <td>0.0587</td>
      <td>1.7707</td>
      <td>6.0005</td>
      <td>2.0571</td>
      <td>0.8311</td>
      <td>0.1165</td>
      <td>0.1550</td>
      <td>0.4186</td>
      <td>0.6507</td>
      <td>0.0009</td>
      <td>18.1102</td>
      <td>0.0508</td>
      <td>1.8495</td>
      <td>0.000</td>
      <td>0.0061</td>
      <td>0.6463</td>
      <td>2.3041</td>
      <td>45.0722</td>
      <td>6.8</td>
      <td>3</td>
      <td>0.050049</td>
      <td>0.001144</td>
      <td>0.027440</td>
      <td>0.021465</td>
      <td>32522000.0</td>
    </tr>
    <tr>
      <th>4</th>
      <td>Antigua and Barbuda</td>
      <td>3.5764</td>
      <td>0.0087</td>
      <td>16.6613</td>
      <td>0.0000</td>
      <td>5.9960</td>
      <td>0.2274</td>
      <td>4.1489</td>
      <td>10.7451</td>
      <td>5.6888</td>
      <td>6.3663</td>
      <td>0.7139</td>
      <td>0.2219</td>
      <td>0.2172</td>
      <td>0.1840</td>
      <td>0.1524</td>
      <td>1.4522</td>
      <td>0.1564</td>
      <td>3.8749</td>
      <td>0.000</td>
      <td>0.0253</td>
      <td>0.8102</td>
      <td>5.4495</td>
      <td>33.3233</td>
      <td>19.1</td>
      <td>2</td>
      <td>0.151020</td>
      <td>0.005102</td>
      <td>0.140816</td>
      <td>0.005102</td>
      <td>98000.0</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>165</th>
      <td>Venezuela (Bolivarian Republic of)</td>
      <td>2.5952</td>
      <td>0.0403</td>
      <td>14.7565</td>
      <td>0.0000</td>
      <td>12.9253</td>
      <td>0.3389</td>
      <td>0.9456</td>
      <td>7.6460</td>
      <td>3.8328</td>
      <td>9.3920</td>
      <td>0.0702</td>
      <td>0.2078</td>
      <td>0.0281</td>
      <td>0.3342</td>
      <td>0.0009</td>
      <td>2.5643</td>
      <td>0.1479</td>
      <td>3.4106</td>
      <td>0.000</td>
      <td>0.0009</td>
      <td>1.3734</td>
      <td>4.1474</td>
      <td>35.2416</td>
      <td>25.2</td>
      <td>3</td>
      <td>0.377466</td>
      <td>0.003351</td>
      <td>0.359703</td>
      <td>0.014411</td>
      <td>28645000.0</td>
    </tr>
    <tr>
      <th>166</th>
      <td>Vietnam</td>
      <td>1.4591</td>
      <td>0.1640</td>
      <td>8.5765</td>
      <td>0.0042</td>
      <td>16.8740</td>
      <td>0.3077</td>
      <td>2.6392</td>
      <td>5.9029</td>
      <td>4.4382</td>
      <td>0.6069</td>
      <td>0.0126</td>
      <td>0.4149</td>
      <td>0.8410</td>
      <td>0.2032</td>
      <td>0.2074</td>
      <td>1.0596</td>
      <td>0.2880</td>
      <td>1.2846</td>
      <td>0.815</td>
      <td>0.3070</td>
      <td>0.2201</td>
      <td>11.9508</td>
      <td>41.4232</td>
      <td>2.1</td>
      <td>2</td>
      <td>0.001457</td>
      <td>0.000036</td>
      <td>0.001295</td>
      <td>0.000126</td>
      <td>96209000.0</td>
    </tr>
    <tr>
      <th>167</th>
      <td>Yemen</td>
      <td>0.0364</td>
      <td>0.0446</td>
      <td>5.7874</td>
      <td>0.0000</td>
      <td>27.2077</td>
      <td>0.2579</td>
      <td>0.5240</td>
      <td>5.1344</td>
      <td>2.7871</td>
      <td>1.8911</td>
      <td>0.2033</td>
      <td>0.2827</td>
      <td>0.0893</td>
      <td>0.8645</td>
      <td>0.0347</td>
      <td>1.0794</td>
      <td>0.2199</td>
      <td>5.0468</td>
      <td>0.000</td>
      <td>0.0017</td>
      <td>1.0811</td>
      <td>3.2135</td>
      <td>44.2126</td>
      <td>14.1</td>
      <td>3</td>
      <td>0.006987</td>
      <td>0.002032</td>
      <td>0.004640</td>
      <td>0.000315</td>
      <td>29826000.0</td>
    </tr>
    <tr>
      <th>168</th>
      <td>Zambia</td>
      <td>5.7360</td>
      <td>0.0829</td>
      <td>6.0197</td>
      <td>0.0000</td>
      <td>21.1938</td>
      <td>0.3399</td>
      <td>1.6924</td>
      <td>1.0183</td>
      <td>1.8427</td>
      <td>1.7570</td>
      <td>0.2149</td>
      <td>0.3048</td>
      <td>1.8736</td>
      <td>0.1756</td>
      <td>0.0478</td>
      <td>7.9649</td>
      <td>0.0618</td>
      <td>1.5632</td>
      <td>0.000</td>
      <td>0.0014</td>
      <td>0.6657</td>
      <td>3.4649</td>
      <td>43.9789</td>
      <td>6.5</td>
      <td>3</td>
      <td>0.099663</td>
      <td>0.001996</td>
      <td>0.094696</td>
      <td>0.002970</td>
      <td>18384000.0</td>
    </tr>
    <tr>
      <th>169</th>
      <td>Zimbabwe</td>
      <td>4.0552</td>
      <td>0.0755</td>
      <td>8.1489</td>
      <td>0.0000</td>
      <td>22.6240</td>
      <td>0.2678</td>
      <td>0.5518</td>
      <td>2.2000</td>
      <td>2.6142</td>
      <td>4.4310</td>
      <td>0.2012</td>
      <td>0.2086</td>
      <td>0.4498</td>
      <td>0.4261</td>
      <td>0.0252</td>
      <td>2.9870</td>
      <td>0.1494</td>
      <td>4.6485</td>
      <td>0.000</td>
      <td>0.0518</td>
      <td>1.7103</td>
      <td>2.3213</td>
      <td>41.8526</td>
      <td>12.3</td>
      <td>3</td>
      <td>0.076418</td>
      <td>0.002079</td>
      <td>0.064280</td>
      <td>0.010059</td>
      <td>14863000.0</td>
    </tr>
  </tbody>
</table>
<p>170 rows × 31 columns</p>
</div>



# フィーチャーとターゲットの選択


```python
data = data.drop('Country', axis=1)
```


```python
data = data.drop(['Confirmed', 'Recovered', 'Active'], axis=1)
```


```python
pd.qcut(data['Deaths'], q=2, labels=[0, 1]).value_counts()
```




    1    85
    0    85
    Name: Deaths, dtype: int64




```python
data['Death'] = pd.qcut(data['Deaths'], q=2, labels=[0, 1])
```

# 分割とスケーリング


```python
y = data['Death']
X = data.drop('Death', axis=1)
```


```python
scaler = sp.StandardScaler()
X = scaler.fit_transform(X)
```


```python
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.8)
```

# トレーニング


```python
X.shape
```




    (170, 27)




```python
model = tf.keras.Sequential([
    tf.keras.layers.Dense(64, activation='relu', input_shape=(27,)),
    tf.keras.layers.Dense(64, activation='relu'),
    tf.keras.layers.Dense(1, activation='sigmoid'),
])

model.summary()

model.compile(
    optimizer='adam',
    loss='binary_crossentropy',
    metrics=[
             'accuracy',
             tf.keras.metrics.AUC(name='auc'),
             ],
)

batch_size = 64
epochs = 100

history = model.fit(
    X_train,
    y_train,
    validation_split=0.2,
    batch_size=batch_size,
    epochs=epochs,
    verbose=0,
)
```

    Model: "sequential_1"
    _________________________________________________________________
    Layer (type)                 Output Shape              Param #   
    =================================================================
    dense_3 (Dense)              (None, 64)                1792      
    _________________________________________________________________
    dense_4 (Dense)              (None, 64)                4160      
    _________________________________________________________________
    dense_5 (Dense)              (None, 1)                 65        
    =================================================================
    Total params: 6,017
    Trainable params: 6,017
    Non-trainable params: 0
    _________________________________________________________________


# 結果


```python
plt.figure(figsize=(14, 10))

epochs_range = range(1, epochs+1)
train_loss = history.history['loss']
val_loss = history.history['val_loss']

plt.plot(epochs_range, train_loss, label='Training Loss')
plt.plot(epochs_range, val_loss, label='Validation Loss')

plt.title('Training and Validation Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.legend()

plt.show()
```


![COVID_19_Healthy_Diet_Dataset_38_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/141539/69c6a055-b4a7-0142-119a-f51da8d80b31.png)



```python
np.argmin(val_loss)
```




    28




```python
model.evaluate(X_test, y_test)
```

    2/2 [==============================] - 0s 5ms/step - loss: 0.3192 - accuracy: 0.9118 - auc: 0.9386





    [0.3191758096218109, 0.9117646813392639, 0.9385964870452881]