OneHotEncoder
A class in scikit-learn that implements one-hot encoding, converting categorical features into a binary feature matrix and capable of handling categories unseen in new data.
Timeline (last 90 days)
OneHotEncoder is the class in scikit-learn that implements one-hot encoding; it can automatically identify the categories in the training data and handle unseen categories in new data (by ignoring them or raising an error).
OneHotEncoder returns a sparse matrix (scipy.sparse format) by default; when ColumnTransformer combines multiple transformers, the sparse_threshold parameter (default 0.3) controls the output format: if the sparsity (proportion of zero elements) of the concatenated matrix exceeds the threshold, a sparse matrix is output; otherwise, a dense array is output.
By setting OneHotEncoder(sparse_output=False) or adjusting ColumnTransformer's sparse_threshold parameter, one-hot encoding can be made to output a dense array.
All Facts (3)
OneHotEncoder is the class in scikit-learn that implements one-hot encoding; it can automatically identify the categories in the training data and handle unseen categories in new data (by ignoring them or raising an error).
50%UnverifiedOneHotEncoder returns a sparse matrix (scipy.sparse format) by default; when ColumnTransformer combines multiple transformers, the sparse_threshold parameter (default 0.3) controls the output format: if the sparsity (proportion of zero elements) of the concatenated matrix exceeds the threshold, a sparse matrix is output; otherwise, a dense array is output.
50%UnverifiedBy setting OneHotEncoder(sparse_output=False) or adjusting ColumnTransformer's sparse_threshold parameter, one-hot encoding can be made to output a dense array.
50%