Perhaps just factor out `n_samples = _num_samples(X)` before `if is_multilabel`.