Learn practical skills, build real-world projects, and advance your career

Insurance cost prediction using linear regression

Make a submisson here: https://jovian.ai/learn/deep-learning-with-pytorch-zero-to-gans/assignment/assignment-2-train-your-first-model

In this assignment we're going to use information like a person's age, sex, BMI, no. of children and smoking habit to predict the price of yearly medical bills. This kind of model is useful for insurance companies to determine the yearly insurance premium for a person. The dataset for this problem is taken from Kaggle.

We will create a model with the following steps:

  1. Download and explore the dataset
  2. Prepare the dataset for training
  3. Create a linear regression model
  4. Train the model to fit the data
  5. Make predictions using the trained model

This assignment builds upon the concepts from the first 2 lessons. It will help to review these Jupyter notebooks:

As you go through this notebook, you will find a ??? in certain places. Your job is to replace the ??? with appropriate code or values, to ensure that the notebook runs properly end-to-end . In some cases, you'll be required to choose some hyperparameters (learning rate, batch size etc.). Try to experiment with the hypeparameters to get the lowest loss.

! pip install seaborn
Collecting seaborn Using cached seaborn-0.11.0-py3-none-any.whl (283 kB) Requirement already satisfied: matplotlib>=2.2 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from seaborn) (3.3.3) Requirement already satisfied: pandas>=0.23 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from seaborn) (1.1.5) Requirement already satisfied: numpy>=1.15 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from seaborn) (1.19.4) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from matplotlib>=2.2->seaborn) (2.4.7) Requirement already satisfied: pillow>=6.2.0 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from matplotlib>=2.2->seaborn) (8.0.1) Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from matplotlib>=2.2->seaborn) (1.3.1) Requirement already satisfied: python-dateutil>=2.1 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from matplotlib>=2.2->seaborn) (2.8.1) Requirement already satisfied: cycler>=0.10 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from matplotlib>=2.2->seaborn) (0.10.0) Requirement already satisfied: numpy>=1.15 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from seaborn) (1.19.4) Requirement already satisfied: six in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from cycler>=0.10->matplotlib>=2.2->seaborn) (1.15.0) Requirement already satisfied: python-dateutil>=2.1 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from matplotlib>=2.2->seaborn) (2.8.1) Requirement already satisfied: numpy>=1.15 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from seaborn) (1.19.4) Requirement already satisfied: pytz>=2017.2 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from pandas>=0.23->seaborn) (2020.4) Requirement already satisfied: six in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from cycler>=0.10->matplotlib>=2.2->seaborn) (1.15.0) Collecting scipy>=1.0 Downloading scipy-1.5.4-cp38-cp38-win_amd64.whl (31.4 MB) Requirement already satisfied: numpy>=1.15 in c:\users\dnabh\anaconda3\envs\jovian\lib\site-packages (from seaborn) (1.19.4) Installing collected packages: scipy, seaborn Successfully installed scipy-1.5.4 seaborn-0.11.0
# 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
import torch
import jovian
import torchvision
import torch.nn as nn
import pandas as pd
import matplotlib.pyplot as plt
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