我的设置是jupyter 4.0.0,python 2.7.6,rpy2 2.7.0,R 3.2.2
我正在尝试使用该软件包" imputeR"。
当我直接从R使用它时,它可以正常工作:
data = read.csv("./data/cs-training.csv")
data$SeriousDlqin2yrs <- NULL
imputed = impute(data, lmFun = "lassoR")
使用以下输出:
Imputation task is: Regression
iteration 1 using lassoR in progress...done!
Difference after iteration 1 is 0.0006133373
iteration 2 using lassoR in progress...done!
Difference after iteration 2 is 3.031679e-07
iteration 3 using lassoR in progress...done!
Difference after iteration 3 is 6.417477e-11
iteration 4 using lassoR in progress...done!
Difference after iteration 4 is 1.919108e-10
来自python,通过使用rpy2,不幸的是它失败了,我还没有能够解决这个问题......任何想法?
import pandas as pd
df = pd.read_csv("../data/cs-training.csv")
from rpy2.robjects.packages import importr
import rpy2.robjects.numpy2ri
rpy2.robjects.numpy2ri.activate()
imputeR = importr('imputeR')
impute = imputeR.impute
imputeR.impute(df2i.as_matrix(),lmFun="lassoR")
这是我得到的标准输出
Imputation task is: Regression
iteration 1 using lassoR in progress...
/home/vagrant/.virtualenvs/venvpy2/local/lib/python2.7/site-packages/rpy2/robjects/functions.py:106: UserWarning: Error in `colnames<-`(`*tmp*`, value = c("x1", "x2", "x3", "x4", "x5", :
length of 'dimnames' [2] not equal to array extent
res = super(Function, self).__call__(*new_args, **new_kwargs)
---------------------------------------------------------------------------
RRuntimeError Traceback (most recent call last)
<ipython-input-12-bd8bd78310aa> in <module>()
8 df2i = df.drop("SeriousDlqin2yrs",axis=1)
9
---> 10 imputeR.impute(df2i.as_matrix(),lmFun="lassoR")
/home/vagrant/.virtualenvs/venvpy2/local/lib/python2.7/site-packages/rpy2/robjects/functions.pyc in __call__(self, *args, **kwargs)
176 v = kwargs.pop(k)
177 kwargs[r_k] = v
--> 178 return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
179
180 pattern_link = re.compile(r'\\link\{(.+?)\}')
/home/vagrant/.virtualenvs/venvpy2/local/lib/python2.7/site-packages/rpy2/robjects/functions.pyc in __call__(self, *args, **kwargs)
104 for k, v in kwargs.items():
105 new_kwargs[k] = conversion.py2ri(v)
--> 106 res = super(Function, self).__call__(*new_args, **new_kwargs)
107 res = conversion.ri2ro(res)
108 return res
RRuntimeError: Error in `colnames<-`(`*tmp*`, value = c("x1", "x2", "x3", "x4", "x5", :
length of 'dimnames' [2] not equal to array extent