Learn practical skills, build real-world projects, and advance your career
# Uncomment and run the appropriate command for your operating system, if required

# Linux / Binder
# !pip install numpy matplotlib pandas torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# Windows
!pip install numpy matplotlib pandas torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# MacOS
# !pip install numpy matplotlib pandas torch torchvision torchaudio
Looking in links: https://download.pytorch.org/whl/torch_stable.html Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (1.18.5) Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (3.2.2) Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages (1.1.4) Collecting torch==1.7.0+cpu Downloading https://download.pytorch.org/whl/cpu/torch-1.7.0%2Bcpu-cp36-cp36m-linux_x86_64.whl (159.3MB) |████████████████████████████████| 159.3MB 77kB/s Collecting torchvision==0.8.1+cpu Downloading https://download.pytorch.org/whl/cpu/torchvision-0.8.1%2Bcpu-cp36-cp36m-linux_x86_64.whl (11.8MB) |████████████████████████████████| 11.8MB 59.1MB/s Collecting torchaudio==0.7.0 Downloading https://files.pythonhosted.org/packages/3f/23/6b54106b3de029d3f10cf8debc302491c17630357449c900d6209665b302/torchaudio-0.7.0-cp36-cp36m-manylinux1_x86_64.whl (7.6MB) |████████████████████████████████| 7.6MB 8.0MB/s Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib) (2.4.7) Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib) (1.3.1) Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib) (2.8.1) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib) (0.10.0) Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas) (2018.9) Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from torch==1.7.0+cpu) (0.16.0) Requirement already satisfied: dataclasses in /usr/local/lib/python3.6/dist-packages (from torch==1.7.0+cpu) (0.8) Requirement already satisfied: typing-extensions in /usr/local/lib/python3.6/dist-packages (from torch==1.7.0+cpu) (3.7.4.3) Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.6/dist-packages (from torchvision==0.8.1+cpu) (7.0.0) Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.1->matplotlib) (1.15.0) Installing collected packages: torch, torchvision, torchaudio Found existing installation: torch 1.7.0+cu101 Uninstalling torch-1.7.0+cu101: Successfully uninstalled torch-1.7.0+cu101 Found existing installation: torchvision 0.8.1+cu101 Uninstalling torchvision-0.8.1+cu101: Successfully uninstalled torchvision-0.8.1+cu101 Successfully installed torch-1.7.0+cpu torchaudio-0.7.0 torchvision-0.8.1+cpu
import torch
import jovian
import torchvision
import torch.nn as nn
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import torch.nn.functional as F
from torchvision.datasets.utils import download_url
from torch.utils.data import DataLoader, TensorDataset, random_split
project_name='02-insurance-linear-regression' # will be used by jovian.commit

Step 1: Download and explore the data

Let us begin by downloading the data. We'll use the download_url function from PyTorch to get the data as a CSV (comma-separated values) file.

DATASET_URL = "https://hub.jovian.ml/wp-content/uploads/2020/05/insurance.csv"
DATA_FILENAME = "insurance.csv"
download_url(DATASET_URL, '.')
HBox(children=(FloatProgress(value=1.0, bar_style='info', max=1.0), HTML(value='')))