skfolio.utils.validation.validate_cross_sectional_data#
- skfolio.utils.validation.validate_cross_sectional_data(_estimator, /, X, y='no_validation', cs_weights=None, *, reset=True, copy=False)[source]#
Validate cross-sectional data.
This helper follows the design of scikit-learn’s
validate_dataand is specialized for cross-sectional arrays with shape(n_observations, n_assets, n_features). The targetyand the optional cross-sectional weights must have shape(n_observations, n_assets).Missing values encoded as NaN are allowed in
Xandy. Infinite values are rejected. The weights must be finite and non-negative.- Parameters:
- _estimatorestimator instance
Estimator on which
n_features_in_is set or checked.- Xarray-like of shape (n_observations, n_assets, n_features)
Input feature tensor.
- yarray-like of shape (n_observations, n_assets), None, or “no_validation”, default=”no_validation”
Target values.
"no_validation": skip target validation and return only the validatedX. This is the default and is used by methods likepredictthat only needX.None: skip target validation, but check the estimator’starget_tags.requiredtag. If the tag isTrue, aValueErroris raised.array-like: validate as a numeric 2D array.
- cs_weightsarray-like of shape (n_observations, n_assets), optional
Cross-sectional weights for each (observation, asset) pair.
Nonewithyprovided: return a matrix of ones.Nonewithyskipped: weights are not validated.array-like: validate as a finite, non-negative 2D array.
- resetbool, default=True
If
True, setn_features_in_on the estimator. IfFalse, check consistency with the stored number of features.- copybool, default=False
If
True, force a copy of the validated arrays.
- Returns:
- X_validatedndarray of shape (n_observations, n_assets, n_features)
Validated feature tensor, returned alone when
yis"no_validation"orNone.- X_validated, y_validated, cs_weights_validatedtuple of ndarrays
Validated
X,y, and weights, returned whenyis an array-like.
- Raises:
- ValueError
If
Xis not a 3D array.- ValueError
If
yisNoneand the estimator’starget_tags.requiredtag isTrue.- ValueError
If
yis provided but its shape does not match the first two dimensions ofX.- ValueError
If
cs_weightsis provided withouty.- ValueError
If
cs_weightscontains negative or non-finite values.- ValueError
If
cs_weightsshape does not match the first two dimensions ofX.- ValueError
If
resetisFalseand the number of features inXdiffers fromn_features_in_.