0
import numpy as np
 import pandas as pd
 import matplotlib.pyplot as plt
 from statsmodels.tsa.statespace.sarimax import SARIMAX
 from keras.models import Sequential
 from keras.layers import Dense
 from keras.optimizers import Adam
             days=np.array([7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45])

feed1 = np.array([6.72,8.57,10.05,11.68,12.82,11.16,12.43,14])
feed2 = np.array([6.83,8.62,10.76,12.2,13.12,13.14,14.66,15.65])
feed3 = np.array([6.64,8.21,9.79,11.24,12.44,13.36,13.77,15.13])
feed4 = np.array([7.27,9.16,10.83,11.74,13.02,13.02,13.89,14.97])

data = {'days': days, 'feed1': feed1, 'feed2': feed2, 'feed3': feed3, 'feed4': feed4}

df = pd.DataFrame(data)
df.set_index('days', inplace=True)
plt.figure(figsize=(10,5))
plt.plot(df.index, df['feed1'], label='Feed 1')
plt.plot(df.index, df['feed2'], label='Feed 2')
plt.plot(df.index, df['feed3'], label='Feed 3')
plt.plot(df.index, df['feed4'], label='Feed 4')
plt.legend(loc='upper left')
plt.title('Input Data')
plt.xlabel('Days')
plt.ylabel('Feed')
plt.show()
train_size = int(len(df) * 0.7)
train, test = df.iloc[:train_size], df.iloc[train_size:]

` ValueError Traceback (most recent call last) Cell In[6], line 17 13 feed4 = np.array([7.27,9.16,10.83,11.74,13.02,13.02,13.89,14.97]) 15 data = {'days': days, 'feed1': feed1, 'feed2': feed2, 'feed3': feed3, 'feed4': feed4} ---> 17 df = pd.DataFrame(data) 18 df.set_index('days', inplace=True) 19 plt.figure(figsize=(10,5))

 File ~\anaconda3\lib\site-packages\pandas\core\frame.py:664, in DataFrame.__init__(self, data, index,   columns, dtype, copy)
 658     mgr = self._init_mgr(
 659         data, axes={"index": index, "columns": columns}, dtype=dtype, copy=copy
 660     )
 662 elif isinstance(data, dict):
 663     # GH#38939 de facto copy defaults to False only in non-dict cases
 --> 664     mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
665 elif isinstance(data, ma.MaskedArray):
666     import numpy.ma.mrecords as mrecords

File ~\anaconda3\lib\site-packages\pandas\core\internals\construction.py:493, in dict_to_mgr(data, index, columns, dtype, typ, copy)
489     else:
490         # dtype check to exclude e.g. range objects, scalars
491         arrays = [x.copy() if hasattr(x, "dtype") else x for x in arrays]
--> 493 return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)

File ~\anaconda3\lib\site-packages\pandas\core\internals\construction.py:118, in arrays_to_mgr(arrays, columns, index, dtype, verify_integrity, typ, consolidate)
115 if verify_integrity:
116     # figure out the index, if necessary
117     if index is None:
--> 118         index = _extract_index(arrays)
119     else:
120         index = ensure_index(index)

File ~\anaconda3\lib\site-packages\pandas\core\internals\construction.py:666, in _extract_index(data)
664 lengths = list(set(raw_lengths))
665 if len(lengths) > 1:
--> 666     raise ValueError("All arrays must be of the same length")
668 if have_dicts:
669     raise ValueError(
670         "Mixing dicts with non-Series may lead to ambiguous ordering."
671     )

ValueError: All arrays must be of the same length

0 Answers0