模型中数组的输入数据格式设置问题

2024-07-08 15:40:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用一个函数(对数周期幂律),代码示例中的输入价格如下所示:

Price input

但是,当我尝试导入我拥有的数据时,无论是csv还是txt,都会出现问题。事实上,我猜这就是问题所在,因为其余的都差不多

代码与pypi.org页面中显示的代码几乎完全相同 (https://pypi.org/project/lppls/):

data = data_loader.sp500()
time = np.linspace(0, len(data)-1, len(data))
price = np.log(data['Adj Close'].values)
# create Mx2 matrix (expected format for LPPLS observations)
observations = np.array([time, price])
MAX_SEARCHES = 25
lppls_model = lppls.LPPLS(observations=observations)
tc, m, w, a, b, c, c1, c2 = lppls_model.fit(observations, MAX_SEARCHES, minimizer='Nelder-Mead')
# visualize the fit
lppls_model.plot_fit()

唯一的变化是我导入的数据,它一直在说“IndexError:数组索引太多”

这是我的密码:

retdji = pd.read_csv('mdji.csv')
content = np.array(retdji.transpose())
observations = np.array([time, content])
MAX_SEARCHES = 25
lppls_model = lppls.LPPLS(observations=observations)
# fit the model to the data and get back the params
tc,m,w,a,b,c,c1,c2 = lppls_model.fit(observations, MAX_SEARCHES, minimizer='Nelder-Mead')
# visualize the fit
lppls_model.plot_fit()

那么,如果我有这种格式的数据,我应该如何处理它,以便模型能够接受它? 提前谢谢

my data


Tags: csvthe数据代码datamodeltimenp

热门问题