Dendrobates
Dendrobates

Reputation: 3534

Python statsmodels.imputation.mice: shape mismatch

I try to use the MICE module of statsmodels to impute my dataset. However, I keep getting errors over some dimension which I don't understand.

Reproducable code here:

# Impute missing values using MICE
import random
import pandas as pd
import numpy as np
import statsmodels.imputation.mice as mice

df = pd.DataFrame(np.random.randn(50, 4), columns=list('ABCD'))
ix = [(row, col) for row in range(df.shape[0]) for col in range(df.shape[1])]
for row, col in random.sample(ix, int(round(.1*len(ix)))):
    df.iat[row, col] = np.nan

imp = mice.MICEData(df)
imp.update_all(10)

And the error I get:

ValueError: shape mismatch: value array of shape (2,1) 
could not be broadcast to indexing result of shape (2,)

Upvotes: 0

Views: 1380

Answers (1)

chris
chris

Reputation: 1322

I think it's a known bug: https://github.com/statsmodels/statsmodels/issues/4129 Looks like it was fixed in their source repo, but not released yet. You could try grabbing their master branch and installing manually: http://www.statsmodels.org/dev/install.html

Upvotes: 3

Related Questions