Answers.Body: <p>The score should be better with scaling, or not worse at least.
  Check the indexing. The 13th column has the index 12, because index is zero-based. Also, if you want to leave out the 2 last categorical columns it should be <code>columns[:-2]</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-11T15:42:54.600Z
Answers.Text: Good catch and thanks! I used the proper mean and standard deviation and I got much closer RMSE scores
Answers.UserDisplayName: pentavol
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-08T10:29:53.167Z
Answers.LastActivityDate: 2021-06-08T10:29:53.167Z
Answers.UserDisplayName: Kirill Fedyanin
Body: <p>I use PyTorch for training a simple neural net for a regression task on a dataset with 12 numerical features + target (target is the 13th column) + 2 categorical features</p>
  <p>Before training, I execute</p>
  <pre><code># numeric_columns = numeric_columns[:-1]
  scaler = StandardScaler()
  scaler.fit(df_train[numeric_columns]])
  </code></pre>
  <p>Also, in my custom <code>torch.util.data.Dataset</code> I scale the data using my <code>scaler</code> object.
  After each epoch, I evaluate the RMSE(&quot;reversed scaled&quot; prediction, non-scaled target), like the following:</p>
  <pre><code>y_pred = (y_pred * self.scaler.scale_[13]) + self.scaler.mean_[13] 
  loss += self.criterion(y_pred , y_true).item()
  </code></pre>
  <p>RMSE if I don't scale the target (the first comment would be uncommented and the y_pred row would be commented) is around 0.95 (I tried multiple hyperparameters)
  RMSE if I scale the target is 1.7</p>
  <p>The target has mean 3.3 and standard deviation of 2.</p>
  <p>What am I doing wrong? I thought scaling the target is a must when dealing with neural networks.</p>
  
Tags: <neural-networks><pytorch>
Title: Why do I have better RMSE when I don't scale the target?
UserDisplayName: pentavol
ThreadText: # Why do I have better RMSE when I don't scale the target?
  
  (Asked by: username_0 on 2021-06-07)
  
  I use PyTorch for training a simple neural net for a regression task on a dataset with 12 numerical features + target (target is the 13th column) + 2 categorical features
  Before training, I execute
  # numeric_columns = numeric_columns[:-1]
  scaler = StandardScaler()
  scaler.fit(df_train[numeric_columns]])
  
  Also, in my custom torch.util.data.Dataset I scale the data using my scaler object.
  After each epoch, I evaluate the RMSE("reversed scaled" prediction, non-scaled target), like the following:
  y_pred = (y_pred * self.scaler.scale_[13]) + self.scaler.mean_[13] 
  loss += self.criterion(y_pred , y_true).item()
  
  RMSE if I don't scale the target (the first comment would be uncommented and the y_pred row would be commented) is around 0.95 (I tried multiple hyperparameters)
  RMSE if I scale the target is 1.7
  The target has mean 3.3 and standard deviation of 2.
  What am I doing wrong? I thought scaling the target is a must when dealing with neural networks.
  
  **Tags:** neural-networks, pytorch
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-06-08. Score: 0 | Accepted answer
  
  The score should be better with scaling, or not worse at least.
  Check the indexing. The 13th column has the index 12, because index is zero-based. Also, if you want to leave out the 2 last categorical columns it should be `columns[:-2]`
  
  > **Comments:**
  > **username_0**: Good catch and thanks! I used the proper mean and standard deviation and I got much closer RMSE scores  
  
  ---
  
  