<a id="skfolio-utils-validation-validate-cross-sectional-data"></a>

# skfolio.utils.validation.validate_cross_sectional_data

<a id="skfolio.utils.validation.validate_cross_sectional_data"></a>

### skfolio.utils.validation.validate_cross_sectional_data(\_estimator, /, X, y='no_validation', cs_weights=None, \*, reset=True, copy=False)

Validate cross-sectional data.

This helper follows the design of scikit-learn’s `validate_data` and is specialized
for cross-sectional arrays with shape `(n_observations, n_assets, n_features)`.
The target `y` and the optional cross-sectional weights must have shape
`(n_observations, n_assets)`.

Missing values encoded as NaN are allowed in `X` and `y`. Infinite values
are rejected. The weights must be finite and non-negative.

* **Parameters:**
  **\_estimator** *estimator instance*
  : Estimator on which `n_features_in_` is set or checked.

  **X** *array-like of shape (n_observations, n_assets, n_features)*
  : Input feature tensor.

  **y** *array-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 validated `X`.
      This is the default and is used by methods like `predict` that only need `X`.
    - `None`: skip target validation, but check the estimator’s
      `target_tags.required` tag. If the tag is `True`, a `ValueError` is raised.
    - array-like: validate as a numeric 2D array.

  **cs_weights** *array-like of shape (n_observations, n_assets), optional*
  : Cross-sectional weights for each (observation, asset) pair.
    - `None` with `y` provided: return a matrix of ones.
    - `None` with `y` skipped: weights are not validated.
    - array-like: validate as a finite, non-negative 2D array.

  **reset** *bool, default=True*
  : If `True`, set `n_features_in_` on the estimator. If `False`, check consistency
    with the stored number of features.

  **copy** *bool, default=False*
  : If `True`, force a copy of the validated arrays.
* **Returns:**
  **X_validated** *ndarray of shape (n_observations, n_assets, n_features)*
  : Validated feature tensor, returned alone when `y` is `"no_validation"` or `None`.

  **X_validated, y_validated, cs_weights_validated** *tuple of ndarrays*
  : Validated `X`, `y`, and weights, returned when `y` is an array-like.
* **Raises:**
  ValueError
  : If `X` is not a 3D array.

  ValueError
  : If `y` is `None` and the estimator’s `target_tags.required` tag is `True`.

  ValueError
  : If `y` is provided but its shape does not match the first two dimensions of `X`.

  ValueError
  : If `cs_weights` is provided without `y`.

  ValueError
  : If `cs_weights` contains negative or non-finite values.

  ValueError
  : If `cs_weights` shape does not match the first two dimensions of `X`.

  ValueError
  : If `reset` is `False` and the number of features in `X` differs from
    `n_features_in_`.

