How to calculate precision at K and NDCG for ranking algorithms
Precision at k (precision@k) requires labeled data. Each item needs to be labeled as relevant or not relevant for the given user. 

$$ precision@k = \frac{Number\ of\ relevant\ @k}{Number\ of\ recommended\ items\ @k} $$

Labeling data is independent of train/test split. Train/test split is useful to avoid overfitting and for estimating a model's ablity to generalize.