Description
Describe the workflow you want to enable
Transformers and Estimators accept list of lists of numbers as valid for inputs like X
.
Yet, when it comes to access to some basic attributes of the datasets (like the shape and the dtype which are present for numpy array) or to reach the best performances (e.g. be able to use Cython implementation which only operates on continuous buffers of memory), list of lists of numbers structure is inconvenient.
Also lists of lists really are used for simple examples (such as doctests) but are unlikely used in practice.
Describe your proposed solution
I propose changing inputs validation to always convert list of list of numbers to their associated natural numpy array.
In this context:
- lists of lists of Python
int
will be converted to 2D numpy array ofnp.int64
- lists of lists of Python
float
will be converted to 2D numpy array ofnp.float64
- a
RuntimeError
will be raised if leaf element aren't numbers - a
RuntimeError
will be raised if internals list have different length (the case of ragged array)
There might be some cost and maintenance complexity in converting list of lists to numpy array.
Changes mostly need be made in:
-
BaseEstimator._validate_data
:
Lines 453 to 460 in 1dc23d7
-
sklearn.utils.check_array
:
scikit-learn/sklearn/utils/validation.py
Lines 629 to 644 in 7b0a162
Describe alternatives you've considered, if relevant
Continue supporting list of lists of numbers and introduce utility functions to be able to get basic attributes of the datasets which this structure.
Additional context
Listing references as I find them: