title: Linear Regresion with PyTorch gives NaN values
body: <p>I'm learning regression (<code>Profit</code> vs <code>R&amp;D</code>) with PyTorch. I have created the following script: </p>
  
  <pre><code>url =https://raw.githubusercontent.com/LakshmiPanguluri/Linear_Multiple_Regression/master/50_Startups.csv
  starup = pd.read_csv(url)
  
  profit = np.array(starup['Profit']).reshape(-1,1)
  rd = np.array(starup['R&amp;D Spend']).reshape(-1,1)
  marketing = np.array(starup['Marketing Spend']).reshape(-1,1)
  administration = np.array(starup['Administration']).reshape(-1,1)
  
  profit_torch = torch.from_numpy(profit).float()
  rd_torch = torch.from_numpy(rd).float().requires_grad_(True)
  
  model = nn.Linear(1,1)
  loss_function = nn.MSELoss()
  optimizer = optim.SGD(model.parameters(), lr=0.010)
  
  losses = []
  iterations = 1000
  for i in range(iterations):
    pred = model(rd_torch)
    loss = loss_function(pred, profit_torch)
    losses.append(loss.data)
  
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
  
  print(loss)
  plt.plot(range(iterations), losses)
  tensor(nan, grad_fn=&lt;MeanBackward0&gt;)
  </code></pre>
  
  <p>My question is why it gives me a tensor with NaN values and why the loss is growing up in every iteration.</p>
  
  <p>The plot of the losses is a line with a positive slope:</p>
  
  <p><img src="https://i.stack.imgur.com/GvF6a.jpg" alt="The plot of the losses is a line with a positive slope"></p>
  
  <p><a href="https://github.com/GianCarloTG/Linear-Regression/blob/master/Linear_Regression_Profit_vs_Marketing_spend.ipynb" rel="nofollow noreferrer">Link to the project I've been doing</a></p>