1.1 Regarding Some of The Code in This Book

We will suppress deprecation warnings of future package changes when importing packages (we will also suppress runtime warnings, though they should only be suppressed in cases when it is absolutely sure why they occur) with:

## ['R', '__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'r', 'sys']

We will also need to sometimes reset the working environment between chapters and remove the existing plot instances:

For R code this will be done automatically by running the following lines:

This is a compatibility issue when writing this book to compile both R and Python code at the same time. The functions clear_all() and close_plots() should be omitted in your own code as they are only specifically required for compilation of this book. The reason for compiling the code along with the book format is that it ensures that all of the functionality and output is unchanged with the given code samples and library versions.

An example of how the Python environment is cleared is provided below. Firstly, the variables in the environment are:

## ['R', '__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'clean_env_var', 'clear_all', 'close_plots', 'gc', 'matplotlib', 'plt', 'r', 'sklearn', 'sm', 'sys', 'warnings']

The above depends on your specific Python environment. For example, Spyder IDE has additional global variables, which should not be removed!

Next, we will create some example variables, and load some packages:

Now, the working environment has the following variables:

## ['R', 'VARIABLE_X', '__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'clean_env_var', 'clear_all', 'close_plots', 'gc', 'matplotlib', 'np', 'optimize', 'pd', 'plt', 'r', 'sklearn', 'sm', 'stats', 'sys', 'warnings', 'x1', 'x2', 'x3', 'y']

Next, we clean the environment:

and see that the remaining variables are the ones from the initial environment:

## ['R', '__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'gc', 'r', 'sys', 'warnings']