Hello, permission to ask, I am having a problem in this case the results do not match the expected output can it help with this

Hello Raden,

Can you share the screenshot shown above the value Error: x and y must have same first dimension.

Basically it is telling you have different shapes especially related first dimension.

Need a full pic of that error and not graph to get an idea where is the issue.


ValueError Traceback (most recent call last)
6 plt.figure(figsize=(10, 6))
7 plot_series(time_valid, series_valid)
----> 8 plot_series(time_valid, diff_moving_avg_plus_past)
9 plt.show()

in plot_series(time, series, format, title, label, start, end)
24 def plot_series(time, series, format=“-”, title=“”, label=None, start=0, end=None):
25 “”“Plot the series”“”
—> 26 plt.plot(time[start:end], series[start:end], format, label=label)
27 plt.xlabel(“Time”)
28 plt.ylabel(“Value”)

/opt/conda/lib/python3.8/site-packages/matplotlib/pyplot.py in plot(scalex, scaley, data, *args, **kwargs)
2759 @docstring.copy(Axes.plot)
2760 def plot(*args, scalex=True, scaley=True, data=None, **kwargs):
→ 2761 return gca().plot(
2762 *args, scalex=scalex, scaley=scaley, **({“data”: data} if data
2763 is not None else {}), **kwargs)

/opt/conda/lib/python3.8/site-packages/matplotlib/axes/_axes.py in plot(self, scalex, scaley, data, *args, **kwargs)
1645 “”"
1646 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
→ 1647 lines = [*self._get_lines(*args, data=data, **kwargs)]
1648 for line in lines:
1649 self.add_line(line)

/opt/conda/lib/python3.8/site-packages/matplotlib/axes/_base.py in call(self, *args, **kwargs)
214 this += args[0],
215 args = args[1:]
→ 216 yield from self._plot_args(this, kwargs)
218 def get_next_color(self):

/opt/conda/lib/python3.8/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs)
341 if x.shape[0] != y.shape[0]:
→ 342 raise ValueError(f"x and y must have same first dimension, but "
343 f"have shapes {x.shape} and {y.shape}")
344 if x.ndim > 2 or y.ndim > 2:

ValueError: x and y must have same first dimension, but have shapes (361,) and (0,)
This is how it went wrong


Make sure

GRADED FUNCTION: train_val_split
def train_val_split(time, series, time_step=SPLIT_TIME):

when you are splitting the data, one of args is incorrect especially check between the time_train and series train, and if your time_valid and series_valid codes are correct in relation to position.