Hi there!
I am a begginer in ML and NN, but currently have to develop one at work.
This is something I am interested in pregressed quite a bit, but after being able to predict one value based on one input, I am now facing a wall I cant climb over on my own.
I have 7 inputs (year, month, day, class of the plane, departure, arrival and customly made ‘flight’ which is basically departure + arrival)
I have to be able to predict coefficient based on those inputs (except ‘flight’)
I prepared all the date (it is all in numbers, not strings) and have date from last 3 years (2019-2021 with calcualeted inputs)
I tried solving it manually adjusting weights etc but too many FP.
My x_train tensor is shaped
torch.Size([256817, 7])
and my NN looks like this:
class Net(nn.Module):
def __init__(self, input_size): #input size (1x7)
super(Net, self).__init__()
n1 = 20 #no. nodes in layer 1
n2 = 10 #no. nodes in layer 2
self.fc1 = nn.Linear(input_size, n1)
self.fc2 = nn.Linear(n1, n2)
self.fc3 = nn.Linear(n2, 1)
def forward(self, x):
x = self.fc1(x)
x = torch.relu(self.fc1(x))
x = self.fc2(x)
x = torch.relu(self.fc2(x))
x = self.fc3(x)
return x
- for some reason
model = Net( )
TypeError: init() missing 1 required positional argument: ‘input_size’
gives me following error and if I input 7 as ‘input_size’ I get following
Traceback (most recent call last):
File “C:\Users\User\PycharmProjects\pythonProject1\NN_1103.py”, line 108, in
y_pred = model(X_train)
File “C:\Users\User\anaconda3\lib\site-packages\torch\nn\modules\module.py”, line 1102, in _call_impl
return forward_call(*input, **kwargs)
File “C:\Users\User\PycharmProjects\pythonProject1\NN_1103.py”, line 87, in forward
x = torch.relu(self.fc1(x))
File “C:\Users\User\anaconda3\lib\site-packages\torch\nn\modules\module.py”, line 1102, in _call_impl
return forward_call(*input, **kwargs)
File “C:\Users\User\anaconda3\lib\site-packages\torch\nn\modules\linear.py”, line 103, in forward
return F.linear(input, self.weight, self.bias)
File “C:\Users\User\anaconda3\lib\site-packages\torch\nn\functional.py”, line 1848, in linear
return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (256817x20 and 7x20)
any and all help will be appriciated.
I understand that I am trying to muliply matrixes that cant be multipled but have no idea how to fix it
if i remove model = Net, then
#Backward pass
criterion = nn.MSELoss() #loss function
optimizer = optim.SGD(Net.parameters(), lr=1e-3, momentum=0.9)
gives error:
Traceback (most recent call last):
File “C:\Users\User\PycharmProjects\pythonProject1\NN_1103.py”, line 101, in
optimizer = optim.SGD(Net.parameters(), lr=1e-3, momentum=0.9)
TypeError: parameters() missing 1 required positional argument: ‘self’