Skip to content

Latest commit

 

History

History
114 lines (95 loc) · 6.2 KB

File metadata and controls

114 lines (95 loc) · 6.2 KB

Environment Setup


Table of Contents


Python Environment

In order to run the code examples in this repository, you need to set up a Python environment with all the necessary libraries installed. Below are the requirements and installation instructions for setting up the environment.

General Requirements

  • Python 3.9 or later
  • Jupyter Notebook - All lecture notes and code examples are provided as Jupyter Notebooks.
  • Common Python libraries for data analysis (e.g., notebook, pandas, numpy, matplotlib, seaborn, scikit-learn, etc.)

Installations

Anaconda [Recommended]

The easiest way to set up a Python environment is to install the Anaconda Distribution, which comes with all common libraries and tools for data science and machine learning and the Python executable. This should be sufficient for most of the code examples in this repository. Please make sure to choose the correct version for your operating system.

Python and Pip [Intermediate Users]

If you prefer to set up a Python environment from scratch, you can install Python and the necessary libraries using the pip package manager. Below are the steps.

  1. Install Python 3.9 or later from the official Python website.

  2. To install the current version of the required libraries, run the following command in your terminal:

    pip install -r https://raw.githubusercontent.com/xiangshiyin/machine-learning-for-actuarial-science/refs/heads/main/requirements.txt
  3. To start the Jupyter Notebook server, run the following command in your terminal:

    jupyter notebook
  4. Open the Jupyter Notebook in your browser and navigate to the desired notebook file to run the code examples.

  5. When you are done, deactivate the virtual environment:

    exit

Python and Poetry [Advanced Users]

If you prefer to set up a Python environment from scratch, you can install Python and the necessary libraries using the Poetry package manager. Below are the steps to set up the environment using Poetry.

  1. Install Python 3.9 or later from the official Python website.

  2. Install Poetry by following the instructions on the official Poetry website.

  3. Clone this repository to your local machine.

  4. Navigate to the root directory of the repository and run the following command to install the required dependencies:

    # run the following command if you want to create a virtual environment in the project directory
    poetry config virtualenvs.in-project true
    # run the following command to install the dependencies
    poetry install
  5. Activate the virtual environment created by Poetry:

    poetry shell
  6. Start the Jupyter Notebook server:

    jupyter notebook
  7. Open the Jupyter Notebook in your browser and navigate to the desired notebook file to run the code examples.

  8. When you are done, deactivate the virtual environment:

    exit
  9. You can also run individual notebooks without activating the virtual environment by running the following command:

    poetry run jupyter notebook

Docker [If you are interested in containerization]

The first time you run the Docker container, it will download the image from the Docker Hub, which may take some time depending on your internet connection speed. Subsequent runs will be faster as the image will be cached on your machine.

  1. Install Docker Desktop from the official Docker website.
  2. Clone this repository to your local machine.
  3. Navigate to the root directory of the repository and run the following command
    docker run -it --rm -p 8888:8888 -v "${PWD}":/home/jovyan/work jupyter/scipy-notebook
  4. Open the Jupyter Notebook in your browser by following the instructions in the terminal.
  5. When you are done, stop the Docker container by pressing Ctrl+C in the terminal.
  6. You can also run the Docker container in the background by running the following command:
    docker run -d --rm -p 8888:8888 -v "${PWD}":/home/jovyan/work jupyter/scipy-notebook
  7. To stop the Docker container running in the background, run the following command:
    docker ps
    docker stop <CONTAINER_ID>
    • Replace <CONTAINER_ID> with the actual container ID from the output of the docker ps command.

IDE Setup

In addition to Jupyter Notebook, you may also want to set up an Integrated Development Environment (IDE) for writing and running Python code, such as Visual Studio Code. In fact, you could use Jupyter Notebook within Visual Studio Code by installing the Jupyter extension (check here for more details).

Online Coding Environment

You can also open and run the Jupyter Notebooks in this repository directly in your browser using Google Colab by clicking the Open In Colab button at the top of each notebook.