Multiple-Input Linear Regression works for one dataset but not another
I am trying to run a logistic regression algorithm using Pytorch (and employing a neural network with one hidden layer), and I stumbled upon a problem. I am running the same algorithm for two different input data. My inputs are two-dimensional. The first set of data I created myself, while the second set of data come from real-world data which I got from a csv file, converted to lists and then to pytorch tensors.
For the first input data, the tensor I insert to the logistic regression code is:
 First tensor has rank
 torch.Size([1000, 2]) 
 
and it's given by:
T1= tensor([[ 0.6258,  0.9683],
        [-0.0833,  0.5691],
        [-0.4657, -0.8722],
        ...,
        [ 0.5868, -1.0565],
        [ 0.1611, -0.1716],
        [-0.1515, -0.8408]])

While the tensor for the second set of data is:
Second tensor has rank
 torch.Size([1064, 2]) 
 
and it's given by:
T2= tensor([[918.0600,  74.8220],
        [917.3477,  71.4038],
        [923.0400,  60.6380],
        ...,
        [916.6000,  71.0960],
        [912.6000,  58.4060],
        [921.5300,  77.7020]])

Now, for the first set of data, I get the following result:

So as you can see, the algorithm does a fairly good job with the reb/blue decision region, as most of the red points end up in the red region (and the same with the blue ones).
Now, for the second set of data, I get the following:

As you can see, it paints the whole region in red. I tried playing around with the number of neurons in my hidden layer and the learning rate, number of epochs and some other things, but nothing seems to work. I then thought that it might have to do with x-axis data having much larger values than the y-axis ones so I normalized them by dividing each with their mean, but this did not solve the problem.
The algorithm is the same, but it just doesn't work for this set of data. I was wondering if somebody who's more of an expert than me could have a hunch as to what might be going wrong here.

When you dont normalize the data the model can be easily fooled.
Your train set is composed of 1000 examples that by the looks of it, the majority of the values are in the range [-1, 1].
When you test your model however, you feed it with much much much higher numbers.
The solution is normalization. When you normalize your input your model can be free to learn the true distribution function of the data rather then &quot;memorize&quot; numbers.
You should normalize both the training set and the test set. Then your values will range between 0 and 1 and your network will have much better chance of picking up the desired correlation.
import torch
import torch.nn.functional as f

train = torch.rand((4, 2))*100


tensor([[36.9267,  7.3306],
        [63.5794, 42.9968],
        [61.3316, 67.6096],
        [88.4657, 11.7254]])

f.normalize(train, p=2, dim=1)

tensor([[0.9809, 0.1947],
        [0.8284, 0.5602],
        [0.6719, 0.7407],
        [0.9913, 0.1314]])

