imputing missing values using a predictive model
<p>I am trying to impute missing values in Python and <code>sklearn</code> does not appear to have a method beyond average (mean, median, or mode) imputation. <a href="http://docs.orange.biolab.si/2/reference/rst/Orange.feature.imputation.html#Orange.feature.imputation.Model" rel="nofollow">Orange imputation model</a> seems to provide a viable option. However, it appears <code>Orange.data.Table</code> is not recognizing <code>np.nan</code> or somehow the imputation is failing.</p>

<pre><code>import Orange
import numpy as np

tmp = np.array([[1, 2, np.nan, 5, 8, np.nan], [40, 4, 8, 1, 0.2, 9]])
data = Orange.data.Table(tmp)
imputer = Orange.feature.imputation.ModelConstructor()
imputer.learner_continuous = Orange.classification.tree.TreeLearner(min_subset=20)
imputer = imputer(data )
impdata = imputer(data)
for i in range(0, len(tmp)):
    print impdata[i]
</code></pre>

<p>Output is </p>

<pre><code>[1.000, 2.000, 1.#QO, 5.000, 8.000, 1.#QO]
[40.000, 4.000, 8.000, 1.000, 0.200, 9.000]
</code></pre>

<p>Any idea what I am missing? Thanks!</p>

<p>In Orange v2 you can pass numpy masked arrays into the Orange.data.Table constructor. Modifying your example:</p>

<pre class="lang-python prettyprint-override"><code>import Orange
import numpy as np

tmp = np.array([[1, 2, np.nan, 5, 8, np.nan], [40, 4, 8, 1, 0.2, 9]])
tmp_masked = np.ma.masked_array(tmp, mask=np.isnan(tmp))
data = Orange.data.Table(tmp_masked)
imputer = Orange.feature.imputation.ModelConstructor()
imputer.learner_continuous = Orange.classification.tree.TreeLearner(min_subset=20)
imputer = imputer(data )
impdata = imputer(data)
for i in range(0, len(tmp)):
    print impdata[i]
</code></pre>

python python-2.7 scikit-learn orange imputation