Given a highly imbalanced dataset, demonstrate how you would code a custom sampling strategy to train your model effectively.