Using training samples for eliminating nuisance parameters