我尝试使用MICE module of statsmodels来估算我的数据集。但是,我一直在某些方面遇到错误,我不明白。
此处可再现代码:
# 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)
我得到的错误:
ValueError: shape mismatch: value array of shape (2,1)
could not be broadcast to indexing result of shape (2,)
答案 0 :(得分:2)
我认为这是一个已知错误:https://github.com/statsmodels/statsmodels/issues/4129看起来它已在源代码库中修复,但尚未发布。您可以尝试抓住他们的主分支并手动安装:http://www.statsmodels.org/dev/install.html