<h3 dir="auto">Describe the workflow you want to enable</h3>
<p dir="auto">I Would like to enable <code class="notranslate">KBinsDiscretizer</code> to handle NaNs, in order to create bins representing missing values. This is a bit awkward for ordinal encoding, but makes a lot of sense for one hot encoding, where one can have a dummy variable for NaN values or simply set all dummis of a single feature to zero, meaning the feature value is missing.</p>
<h3 dir="auto">Describe your proposed solution</h3>
<p dir="auto">A few tweaks in <code class="notranslate">fit</code>, <code class="notranslate">transform</code> and <code class="notranslate">inverse_transform</code> are enough to ensure this behaviour, without changing the current behaviour of the transformer. The new estimator has two new parameters in the constructor:</p>
<p dir="auto"><code class="notranslate">nan_handling</code>: {"handle","raise"}, defaults to "raise".<br>
defines the behaviour for hadling NaN. if "handle", the fit process will be performed excluding and the missing values of each column and the transform method will transform only not missing values and after that, a NaN bin is created (of index self.n_bins_ +1)</p>
<p dir="auto"><code class="notranslate">create_nan_dummy</code>: bool<br>
Only applicable if encode == "onehot". Defines whether a new dummy column is created for NaNs or if the dummies of a missing value for a given feature are all set to zero</p>
<h3 dir="auto">Describe alternatives you've considered, if relevant</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Additional context</h3>
<p dir="auto">I Have already implemented a solution for a project of mine. Just wanna know if this feature is intereseting for other people and if it makes sense to merge it into the main project.</p>
<p dir="auto">Missing values, represented as NaN, could be treated as a separate category in discretization. This seems much more sensible to me than imputing the missing data then discretizing.</p>
<p dir="auto">In accordance with recent changes to other preprocessing, NaNs would simply be ignored in calculating <code class="notranslate">fit</code> statistics, and would be passed on to the encoder in <code class="notranslate">transform</code>. I can't recall if we're handling this sensibly in OneHotEncoder yet...</p>