fit_prepare function

Fit and prepare in a cross-validated manner.