Wrong results for diff moving average

C4W1 programming assignment:
I get wrong results when grading diff moving average:
this is my implementation:

any idea why?
image

Dear @rakefetlevy,
I understand that you’re encountering challenges with the implementation, and I’m here to help. However, as per our community guidelines, we cannot share graded code publicly, even if it contains errors. This ensures a fair learning environment for everyone.

To assist you effectively, please share a screenshot of the error message or the output you’re seeing. This way, we can pinpoint where the issue might be. If necessary, a mentor will guide you on how to share your code securely for review.

For now, it looks like your implementation of moving_average_forecast is mostly correct. I suggest double-checking the parts leading up to the error to identify where it might be going wrong. You can also review the ungraded labs. Once you’ve done that, feel free to share the screenshot here, and we’ll take a closer look together.

Looking forward to helping you resolve this!

sure. thank you for telling me that, i removed my code
i added a screen shot of the error

Did it pass the test on the function?

Let me know. If it did not pass, then the implementation of diff_moving_avg is wrong. Check it again. You can refer to the ungraded labs in the week.

no, diff_moving_avg fails
all tests before it pass, see pic
strong text

this is what i see when i run it in my colab:

diff_moving_avg is based on moving_average_forecast which seems to be OK

Click my profile pic and then on message and then send me your notebook. Let me see.

I reviewed your notebook and noticed that the issue is with the hard-coded value in your diff_moving_average function definition. Specifically, the code for # Perform the correct slicing uses a fixed value instead of the function argument. Please update the code to use the function argument instead of the default value of the argument.
Let me know if it works.

1 Like

first, thank you for taking a look!
there is no function diff_moving_avg but it is a variable name, are you suggesting that I sent “30” as hard coded? (for window_size?)

Sorry, my bad. I meant the variable. And yes, you have to use the argument, not it’s default value.

i defined my own variables for window_size and for lag=365 but it didnt seem to help.
" Notice that the window_size has already being defined and that you will need to perform the correct slicing for the series to match the validation period. do you happen to know where the exercise “window_size” is defined?
thank you

In Python while defining functions, I can make some of the parameters optional by giving them a default value. If I call the function without passing the value, the default value is used.

def add(x,y=2):
    return x + y

If I call add(1), it returns 3 because it assumes y is 2 (the default).
If I call add(2,4), it returns 6,this time y is 4.
In this specific assignment, you just pass window_size while defining diff_moving_avg. You do not give it a value.

thanks, i’ll try!