[英]“'x' must be a non-empty numeric vector” rpy2 error: why is it not working?
I am using Colab and Python to find the best fit distribution for my data. 我正在使用Colab和Python为我的数据找到最合适的分布。 I am a newbie in this, so am experiencing a lot of problems.
我是新手,因此遇到了很多问题。 So far, here's my code:
到目前为止,这是我的代码:
from rpy2.robjects import pandas2ri
from rpy2.robjects.packages import importr
MASS = importr('MASS')
pandas2ri.activate()
df_temp = pd.DataFrame()
df_temp["Values"] = [37.50,46.79,48.30,46.04,43.40,39.25]
ri_temp = pandas2ri.py2ri(df_temp)
params_temp = MASS.fitdistr(ri_temp, 'normal')
print(params_temp)
Now, there is a lot going on that I don't understand yet. 现在,有很多事情我还不明白。 Please be as descriptive as possible!:) For instance, I am not getting the idea of why I have to use
pandas2ri.activate()
. 请尽量描述!:)例如,我不知道为什么我必须使用
pandas2ri.activate()
。 The error that my code is producing is this: 我的代码产生的错误是这样的:
/usr/local/lib/python3.6/dist-packages/rpy2/rinterface/__init__.py:146:
RRuntimeWarning: Error in (function (x, densfun, start, ...) :
'x' must be a non-empty numeric vector
... Traceback in between... ......之间的追溯......
warnings.warn(x, RRuntimeWarning)
RRuntimeError: Error in (function (x, densfun, start, ...) :
'x' must be a non-empty numeric vector
So, what's the issue? 那么,问题是什么?
The reason I am using pandas first is that I have my data stored in a list. 我首先使用pandas的原因是我将数据存储在列表中。 If I can avoid using pandas, then what would be the alternative?
如果我可以避免使用熊猫,那会有什么选择呢? When I tried simply parsing
MASS.fitdistr(list, 'normal')
it gives me errors as well. 当我尝试简单地解析
MASS.fitdistr(list, 'normal')
它也给了我错误。 Also, maybe there is a better alternative to using r to find the best fit distribution for a given list data? 另外,使用r找到给定列表数据的最佳拟合分布可能有更好的选择吗? Any recommendations?
有什么建议?
This helped: my_array = np.asarray(my_list)
. 这有助于:
my_array = np.asarray(my_list)
。 And then using the array as my input for: params_temp = MASS.fitdistr(my_array, 'normal')
. 然后使用数组作为我的输入:
params_temp = MASS.fitdistr(my_array, 'normal')
。
Thanks to akrun. 感谢akrun。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.