Add Categorical Feature Support to `IterativeImputer`

### Describe the workflow you want to enable

I want to impute missing values in categorical columns using a similar approach to `IterativeImputer`, which currently works only for continuous data. Specifically, I want to enable the following workflow:

- Identify and handle categorical columns in the dataset
- Use classifier models (e.g., RandomForestClassifier) to impute missing values in categorical columns based on other features
- Integrate with existing pipelines seamlessly, without needing to separate and impute categorical columns manually

### Describe your proposed solution

Extend the current `IterativeImputer` class (or create a new class, such as `IterativeCategoricalImputer`) to handle categorical data:

- Detect categorical columns automatically (e.g., using `dtype='object'` or `category`) or accept them via a `categorical_features` parameter
- Encode the categorical variables using an internal encoder (e.g., `LabelEncoder`)
- Use a classifier model (e.g., `RandomForestClassifier`) instead of a regression model for those columns
- Predict only the missing values, then inverse transform the predictions back to the original categories

This would enable more robust and automatic preprocessing for datasets that have numeric and categorical features.

### Describe alternatives you've considered, if relevant

- Manually encoding categorical variables, using a classifier-based imputation strategy outside of `IterativeImputer`
- Using other libraries like `autoimpute` or `fancyimpute`, which support mixed-type imputation but lack full integration with Scikit-learn pipelines
- Creating separate imputation steps for categorical and numeric features and merging them later, which adds complexity and can introduce data leakage risks

None of these are as clean or pipeline-friendly as a built-in solution.


### Additional context

This feature would make `IterativeImputer` more powerful and suitable for real-world datasets that include both numeric and categorical variables with missing values.

I'm currently working with datasets like this in my own data science projects and would be interested in contributing a prototype or proof-of-concept if this idea is accepted by the maintainers.

COMMENT:
Thanks so much for your response @ogrisel. I appreciate your comments and clarifications!

You were correct in mentioning that the LabelEncoder was not needed for target variables. I was thinking about being consistent across the whole pipeline and assumed it would be added. However, since classifiers encode string labels correctly as part of their work, I can remove that part entirely.

I also really liked your suggestion of taking in separate classifier, regressor, and preprocessor parameters, which adds a lot of 
flexibility and reduces the complexity of the object coming in. 

Your comment about sample_posterior was right on point since it is off by default, I will put it in the documentation. I will also specify that if users need a probabilistic regressor then they should pass one. I will also add the logic to raise NotImplementedError when n_nearest_features is used when the data type is not continuous.

Would it make sense to develop a prototype implementation of a new class called IterativeMixedDataImputer (mainly to not break the behavior of IterativeImputer) and if all goes well we can merge them together or refactor with that or possibly other classes?

Thanks again, and I would like to hear thoughts from @GaelVaroquaux.

Labels: New Feature