<h3 dir="auto">Describe the workflow you want to enable</h3>
<p dir="auto">SimpleImputer.strategy = 'random' will randomly choose a non-NaN value.</p>
<h3 dir="auto">Describe your proposed solution</h3>
<p dir="auto">Find a list of non-NaN indices. Randomly pick one index for each NaN.</p>
<h3 dir="auto">Describe alternatives you've considered, if relevant</h3>
<p dir="auto">Pandas:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# Impute missing NaN values by randomly selecting a non-NaN value
for column in df.columns:
    nan_indexes = df[df[column].isna()].index
    non_nan_values = df[column].dropna().tolist()
    imputed_values = [random.choice(non_nan_values) for _ in range(len(nan_indexes))]
    df.loc[nan_indexes, column] = imputed_values"><pre class="notranslate"><code class="notranslate"># Impute missing NaN values by randomly selecting a non-NaN value
for column in df.columns:
    nan_indexes = df[df[column].isna()].index
    non_nan_values = df[column].dropna().tolist()
    imputed_values = [random.choice(non_nan_values) for _ in range(len(nan_indexes))]
    df.loc[nan_indexes, column] = imputed_values
</code></pre></div>
<h3 dir="auto">Additional context</h3>
<p dir="auto">Let's say you're in the following setting:</p>
<p dir="auto">GOAL: Iteratively tighten a hyperparameter grid.</p>
<ul dir="auto">
<li>You have a broad hyperparameter grid</li>
<li>Some hyperparameter choices disable (i.e. make NaN) other hyperparameter choices.</li>
<li>You do random selection of grid points and get the loss.</li>
<li>You make _isnan a value, true or false, for params that can be NaN.</li>
<li>You impute the missing values for NaNs.</li>
<li>You use decision tree regression to figure out what hyperparameter choices are best.<br>
You tighten your grid iteratively using the above.</li>
</ul>
<p dir="auto">However, one downside is that some of the splits will be misleading, if they involved imputed NaNs. (The split on this hyperparameter value could suggest a particular threshold OR that the governing hyperparameter that created this NaN is important.) A way to reduce this confusion is using random choice when imputing.</p>
<p dir="auto">The purpose would be to provide an unbiased, stochastic, univariate imputer. The imputer would replace missing values by values sampled uniformly at random from the non-missing values of the sample column.</p>
<p dir="auto">This would require to add additional <code class="notranslate">random_state</code> constructor parameter to the class.</p>
<p dir="auto">As for <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="329773579" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/11208" data-hovercard-type="issue" data-hovercard-url="/scikit-learn/scikit-learn/issues/11208/hovercard" href="https://github.com/scikit-learn/scikit-learn/issues/11208">#11208</a> this strategy should work both on numerical and non-numerical dtypes.</p>