🚨 Introducing a python package that helps with machine learning feature engineering during the pandemic! lockdowndates🔥
Tags: python, programming, opensource, showdev
Published: 2022-03-17 12:58:10

Recently during the pandemic if you were training machine learning models with some sort of time element you would have been scrambling to try and reengineer these as I would be confident to say the pandemic made all your forecasts very far from the truth. 

Consumer habits were completely changed and became so unexpected it was hard to forecast. Everyone was left in the dark as to whether we all would be thrown into a complete or partial lockdown.

As a machine learning engineer I had to completely change my approach to training machine learning models during the pandemic. It took a lot of tweaking. The hardest part was training models for consumers in different countries around the world, where restrictions were completely different. This is still a pain for some countries at the moment with restrictions coming and going. 

So, I decided instead of trying to alleviate the damage of the pandemic in our models, why not embrace them? Why not embed them as features in our models for them to learn about? That's why I decided to created **[lockdowndates](https://seanyboi.github.io/lockdowndates/)**

**[lockdowndates](https://seanyboi.github.io/lockdowndates/)* provides all current and past restrictions imposed by governments in over **100** countries worldwide during the pandemic! To get started:

`pip3 install lockdowndates`

(side note: currently we only support `python3.8` and above, this will be changing soon to support `3.6>`)

after installing we import:

```python
from lockdowndates.core import LockdownDates
```

to get restrictions for a single country:

```python
ld = LockdownDates("Aruba", "2022-01-01", "2022-01-08")
lockdown_dates = ld.dates()
lockdown_dates
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>aruba_country_code</th>
      <th>aruba_stay_at_home</th>
    </tr>
    <tr>
      <th>timestamp</th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2022-01-01</th>
      <td>ABW</td>
      <td>2.0</td>
    </tr>
    <tr>
      <th>2022-01-02</th>
      <td>ABW</td>
      <td>2.0</td>
    </tr>
    <tr>
      <th>2022-01-03</th>
      <td>ABW</td>
      <td>2.0</td>
    </tr>
    <tr>
      <th>2022-01-04</th>
      <td>ABW</td>
      <td>2.0</td>
    </tr>
    <tr>
      <th>2022-01-05</th>
      <td>ABW</td>
      <td>2.0</td>
    </tr>
    <tr>
      <th>2022-01-06</th>
      <td>ABW</td>
      <td>2.0</td>
    </tr>
    <tr>
      <th>2022-01-07</th>
      <td>ABW</td>
      <td>2.0</td>
    </tr>
    <tr>
      <th>2022-01-08</th>
      <td>ABW</td>
      <td>2.0</td>
    </tr>
  </tbody>
</table>
</div>

to get restrictions for multiple countries:

```python
ld2 = LockdownDates(["Canada", "Denmark"], "2022-01-01", "2022-01-08")
lockdown_dates = ld2.dates()
lockdown_dates
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>canada_country_code</th>
      <th>denmark_country_code</th>
      <th>canada_stay_at_home</th>
      <th>denmark_stay_at_home</th>
    </tr>
    <tr>
      <th>timestamp</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2022-01-01</th>
      <td>CAN</td>
      <td>DNK</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>2022-01-02</th>
      <td>CAN</td>
      <td>DNK</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>2022-01-03</th>
      <td>CAN</td>
      <td>DNK</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>2022-01-04</th>
      <td>CAN</td>
      <td>DNK</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>2022-01-05</th>
      <td>CAN</td>
      <td>DNK</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>2022-01-06</th>
      <td>CAN</td>
      <td>DNK</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>2022-01-07</th>
      <td>CAN</td>
      <td>DNK</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>2022-01-08</th>
      <td>CAN</td>
      <td>DNK</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
  </tbody>
</table>
</div>

the legend for `stay_at_home` are as follows:

- NaN - No data available for that date.
- 1.0 - recommend not leaving house.
- 2.0 -  require not leaving house with exceptions for daily exercise, grocery shopping, and 'essential' trips.
- 3.0 - require not leaving house with minimal exceptions (eg allowed to leave once a week, or only one person can leave at a time, etc.

**[lockdowndates](https://seanyboi.github.io/lockdowndates/)** contains up to date data thanks to oxford university and their open source data!

I will keep updating **lockdowndates** to contain more restrictions, including restrictions for vaccinated vs non-vaccinated, school restrictions, work from home restrictions and many more! Track our issues **[here](https://github.com/seanyboi/lockdowndates/issues)**.

So next time you feature engineering on your next machine learning project and have tabular data from the during the pandemic, consider **[lockdowndates](https://seanyboi.github.io/lockdowndates/)** to make your life easier and to improve your metrics!

Documentation: **[lockdowndates](https://seanyboi.github.io/lockdowndates/)**

Github Repo: **[lockdowndates](https://github.com/seanyboi/lockdowndates)**