Hi everyone!
I am really new to deep learning. I’m currently working with data set from kaggle competition (https://www.kaggle.com/c/pkdd-15-predict-taxi-service-trajectory-i/overview) where I try to predict lat and long of taxis with neural network.
But I can’t really figure out what is going wrong in my model since I always get the same values for output, although losses are descending.
Here is my code.
I preprocess data as follows:
zf = zipfile.ZipFile('train.csv.zip')
df = pd.read_csv(zf.open('train.csv'), converters={'POLYLINE': lambda x: json.loads(x)[-1:]})
df1 = df.dropna(subset = ['POLYLINE'])
df1 =df1.fillna(1)
df_train, df_test = train_test_split(df1, train_size = 0.1, random_state=0)
df_train['CALL_TYPE'] = pd.factorize(df_train['CALL_TYPE'])[0]
df_train['DAY_TYPE'] = pd.factorize(df_train['DAY_TYPE'])[0]
df_train['MISSING_DATA'] = pd.factorize(df_train['MISSING_DATA'])[0]
df_train['TAXI_ID'] = pd.factorize(df_train['TAXI_ID'])[0]
df_test['CALL_TYPE'] = pd.factorize(df_test['CALL_TYPE'])[0]
df_test['DAY_TYPE'] = pd.factorize(df_test['DAY_TYPE'])[0]
df_test['MISSING_DATA'] = pd.factorize(df_test['MISSING_DATA'])[0]
df_test['TAXI_ID'] = pd.factorize(df_test['TAXI_ID'])[0]
features = df_train.drop('POLYLINE', axis = 1).values #this is final train set
target = df_train['POLYLINE'].values
max_length = max(len(row) for row in target)
max_cols = max([len(row) for batch in target for row in batch])
max_rows = max([len(batch) for batch in target])
padded = [batch + [[0] * (max_cols)] * (max_rows - len(batch)) for batch in target]
padded = torch.tensor([row + [0] * (max_cols - len(row)) for batch in padded for row in batch])
padded = padded.view(-1, max_rows, max_cols)
lat = padded[:,0][:,0]
long = padded[:,0][:,1]
targ = pd.DataFrame() #this is final target variable
targ['lat'] = lat
targ['long'] = long
X = torch.from_numpy(features.astype(np.float32))
y = torch.from_numpy(np.array(targ).astype(np.float32))
Then I build model the following way:
torch.manual_seed(1)
x, y = Variable(X), Variable(y)
net = torch.nn.Sequential(
torch.nn.Linear(8, 20),
torch.nn.LeakyReLU(),
torch.nn.Linear(20, 10),
torch.nn.LeakyReLU(),
torch.nn.Linear(10, 2),
)
optimizer = torch.optim.Adadelta(net.parameters(), lr=0.01)
loss_func = torch.nn.SmoothL1Loss()
BATCH_SIZE = 64
EPOCH = 100
torch_dataset = Data.TensorDataset(x, y)
loader = Data.DataLoader(
dataset=torch_dataset,
batch_size=BATCH_SIZE,
shuffle=True, num_workers=2,)
for epoch in range(EPOCH):
for step, (batch_x, batch_y) in enumerate(loader):
b_x = Variable(batch_x)
b_y = Variable(batch_y)
prediction = net(b_x)
loss = loss_func(prediction, b_y)
optimizer.zero_grad()
loss.backward()
optimizer.step()
if(epoch % 10 == 0):
print('epoch {}, loss {}'.format(epoch, loss.data))
Will really appreciate any help!