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

System setup

If you want to follow along and run the code as you read, you can clone this notebook, install the required dependencies, and start Jupyter by running the following commands on the terminal:

pip install jovian --upgrade # Install the jovian library jovian clone <notebook_id> # Download notebook & dependencies cd 02-linear-regression # Enter the created directory jovian install # Install the dependencies conda activate 02-linear-regression # Activate virtual environment jupyter notebook # Start Jupyter

You can find the notebook_id by cliking the Clone button at the top of this page on Jovian. On older versions of conda, you might need to run source activate 02-linear-regression to activate the environment. For a more detailed explanation of the above steps, check out the System setup section in the previous notebook.

import numpy as np
import torch
# Input (temp, rainfall, humidity)
inputs = np.array([[73, 67, 43], 
                   [91, 88, 64], 
                   [87, 134, 58], 
                   [102, 43, 37], 
                   [69, 96, 70]], dtype='float32')
# Targets (apples, oranges)
targets = np.array([[56, 70], 
                    [81, 101], 
                    [119, 133], 
                    [22, 37], 
                    [103, 119]], dtype='float32')
# Convert inputs and targets to tensors
inputs = torch.tensor(inputs)
targets = torch.tensor(targets)
print(inputs)
print(targets)
tensor([[ 73., 67., 43.], [ 91., 88., 64.], [ 87., 134., 58.], [102., 43., 37.], [ 69., 96., 70.]]) tensor([[ 56., 70.], [ 81., 101.], [119., 133.], [ 22., 37.], [103., 119.]])