Chapter IV
Input validation: check_array and validate_data
check_array and check_X_y (composed together and wrapped by validate_data) form the shared input-validation contract that almost every estimator's fit/predict/transform routes through: they coerce dtypes, enforce 2D shape and minimum sample/feature counts, and reject NaN/Inf unless a config or parameter says otherwise. validate_data additionally records n_features_in_/feature_names_in_ on the estimator, so later calls can detect shape drift, while _fit_context wraps fit() to validate hyperparameters before this data validation ever runs. Understanding this pipeline explains where most of scikit-learn's input error messages come from and why every estimator behaves consistently on bad data.
How a fit() call routes through validation
Estimator.fit(X, y)sklearn/linear_model/_base.py
_fit_context decoratorsklearn/base.py
validate_data()sklearn/utils/validation.py
check_X_y()sklearn/utils/validation.py
_check_n_features()sklearn/utils/validation.py
check_array()sklearn/utils/validation.py
_assert_all_finite()sklearn/utils/validation.py