Kaggle competition: Lyft Motion Prediction for Autonomous Vehicles
<SOS> metric: PostProcessorKernel Kaggle data source: lyft-motion-prediction-autonomous-vehicles<concatenate>
pd.options.display.max_columns=305
def toTapleList(list1,list2):
return list(itertools.product(list1,list2))<load_from_csv>
paths = [
".. /input/lyft-best-performing-public-kernels/lyft-ensembling-raster-sizes.csv",
".. /input/lyft-best-performing-public-kernels/lyft-prediction-with-multi-mode-confidence.csv",
]
weights = [0.4, 0.6]
%%time
train = pd.read_csv('.. /input/train_V2.csv')
 train = reduce_mem_usage(train)
 test = pd.read_csv('.. /input/test_V2.csv')
 test = reduce_mem_usage(test)
 print(train.shape, test.shape )<count_missing_values>
conf_cols = np.array(["conf_0", "conf_1", "conf_2"] )
null_cnt = train.isnull().sum().sort_values()
print(null_cnt[null_cnt > 0])
 train.dropna(inplace=True )<count_unique_values>
xy_cols = [[],[],[]]
for i in range(50):
for j in range(3):
xy_cols[j].append(f"coord_x{j}{i}")
 xy_cols[j].append(f"coord_y{j}{i}")
 xy_cols[0][:10]
for c in ['Id','groupId','matchId']:
print(f'unique [{c}] count:', train[c].nunique() )<count_values>
COLUMNS = ["timestamp", "track_id"] + list(conf_cols)+ xy_cols[0] + xy_cols[1] + xy_cols[2]
for q in ['numGroups == maxPlace','numGroups != maxPlace']:
print(q, ':', len(train.query(q)) )<drop_column>
def sort_df(df, sort_timestamp_track_id=True):
conf_orders = np.argsort(-df[conf_cols].values,1)
 XY = np.stack([df[xy_cols[0]].values,df[xy_cols[1]].values, df[xy_cols[2]].values], axis=1)
 XY = XY[np.arange(len(XY)) [:, None], conf_orders]
df2 = pd.DataFrame(columns = COLUMNS)
 df2["timestamp"] = df["timestamp"].values
df2["track_id"] = df["track_id"].values
df2[xy_cols[0] + xy_cols[1] + xy_cols[2]] = XY.reshape(-1,300)
 df2[conf_cols] = df[conf_cols].values[np.arange(len(df)) [:, None], conf_orders]
if sort_timestamp_track_id:
df2.sort_values(["timestamp", "track_id"], inplace=True)
 df2.reset_index(inplace=True, drop=True)
 return df2
print(group['players in group'].nlargest(5))
del match,group<count_unique_values>
%%time
df = None
for path,w in zip(paths,weights):
print(w, path)
 temp = pd.read_csv(path)
 temp = sort_df(temp)
 temp[COLUMNS[5:]] *= w
if df is None:
df = temp
else:
df[COLUMNS[2:]] += temp[COLUMNS[2:]]
df[conf_cols] /= df[conf_cols].sum(1 ).values[:, None]
sample = pd.read_csv(".. /input/lyft-motion-prediction-autonomous-vehicles/multi_mode_sample_submission.csv")
 df = sample[["timestamp", "track_id"]].merge(df, on=["timestamp", "track_id"])
 sample.shape, df.shape
<count_unique_values><EOS> 
df.to_csv("submission.csv", index=False, float_format='%.6f' )