Linear nn output problem

dreamer: <p>Hi everyone, i build simple linear nn but output of this network is not same as desired result.<br>
I got this result from my network<br>
<img src="https://discuss.pytorch.org/uploads/default/original/2X/e/ea9c8571e2e8b7fd6fa57e198a41550342551525.png" alt="Figure_5" data-base62-sha1="xtt4xZ6U85LOp9pUaPwjjhlZLoh" width="640" height="478"><br>
this is my loss graph<br>
<img src="https://discuss.pytorch.org/uploads/default/original/2X/1/175d6b64d678a1a5cfdc978897dbaaf8d85d9499.png" alt="Figure_6" data-base62-sha1="3kH8c91zp4ld9zUWqxpctaHxlnb" width="640" height="478"><br>
this is the desired result<br>
<img src="https://discuss.pytorch.org/uploads/default/original/2X/4/4b92f0ebc9f706ff83bfeaec4c77205304e69e06.png" alt="Figure_7png" data-base62-sha1="aMyD4eyb7gSGdzMkICrERNNzd78" width="640" height="478"></p>
<p>my codes are:</p>
<pre><code class="lang-auto">class Module(nn.Module):
        def __init__(self, D_in, H1, H2, D_out):
                        super().__init__()
                        self.linear1 = nn.Linear(D_in, H1)
                        self.linear2 = nn.Linear(H1, H2)
                        self.linear3 = nn.Linear(H2, D_out)
        def forward(self, x):
                        x = F.relu(self.linear1(x))  
                        x = F.relu(self.linear2(x))
                        x = self.linear3(x)
                        return x

train_dataset = TensorDataset(train_x, train_y)
train_generator = DataLoader(train_dataset, batch_size=32,shuffle=False)
valid_dataset = TensorDataset(val_x, val_y)
valid_generator = DataLoader(valid_dataset, batch_size=32)
model=Module(3,27,11,1)
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
for e in range(epochs):
  
        running_loss = 0.0
        running_corrects = 0.0
        val_running_loss = 0.0
        val_running_corrects = 0.0
  
        for inputs,out in train_generator:
                
                print(out.size())
                inputs=inputs.to(device)
                out=out.to(device)
                output=model(inputs)
                new_output = torch.squeeze(output)
                print("input size: ",inputs.size())
                loss = criterion(new_output,out)
                print("output size: ",output.size())
                print("out size: ",out.size())
                preds,_=torch.max(new_output,1)
                         
                outputss.append(preds.max().detach().numpy())
                losses.append(loss)
                optimizer.zero_grad()
                loss.backward()
                optimizer.step()
                                                                        
                #outputss.append(outputs.detach().numpy())
                #print(loss.item())

        else:
             with torch.no_grad():
                for val_inputs, val_labels in valid_generator:
                        #val_inputs = val_inputs.view(val_inputs.shape[0], -1)
                        val_inputs=val_inputs.to(device)
                        val_labels=val_labels.to(device)
                        val_outputs = model(val_inputs)
                        val_loss = criterion(val_outputs, val_labels)
                        
                        val_preds,_ = torch.max(val_outputs, 1)
                        val_running_loss_history.append(val_loss)
                        val_running_corrects_history.append(val_preds.max().detach().numpy())
</code></pre>
<p>If you can help me, I will be very thankful</p>

dreamer: <p>Guys, if anyone can help me, i will be very appreciate to him/her</p>

ptrblck: <p>What kind of input data are you using?<br>
Based on the loss curve it looks like your model is still training and the loss goes down.<br>
Have you seen a plateau after a while?</p>

DoubtWang: <p>the loss curve is normal. the result curve is abnormal,<br>
I think that the distribution of the trian and vaild datasets is different.</p>

dreamer: <p>I have dataset which is .csv file and I read them into numpy array</p>

dreamer: <p>Hi, if we said that dataset is 100x then train set is 85x and valid set is 15x so actually they are not so different</p>

ptrblck: <p>Thanks for the information. I’m still unsure, why you’ve stopped the training when the loss was still going down. Did you try to train it a bit longer and check the results?</p>

DoubtWang: <p>Of course, the number of the train and the valid set is different.<br>
My idea is whether the distribution of the two is the same.<br>
u can eandomly split the dataset into train and vaild set, then train your model, and observe the results.</p>

dreamer: <p>Yes, i trained them like 2k epochs and more but result did not change</p>

dreamer: <p>I thought validation set size should be smaller than training set? If I am wrong, can you explain me briefly?</p>
<p>Regards,</p>

DoubtWang: <p>yeah, the train set size should bigger than the validation set size.<br>
My means is that u can randomly split the dataset into train and valid set according to a ratio, e.g., 8:2.<br>
Then, train your model and oberve the results.</p>