Hello. I got this error below.

UnboundLocalError Traceback (most recent call last)

in

5 ones = np.ones(5)

6

----> 7 mse, mae = compute_metrics(zeros, ones)

8 print(f"mse: {mse}, mae: {mae} for series of zeros and prediction of ones\n")

9

in compute_metrics(true_series, forecast)

3

4 ### START CODE HERE

----> 5 mse = mse(y_true, y_pred).numpy()

6 mae = mae(y_true, y_pred).numpy()

7 ### END CODE HERE

UnboundLocalError: local variable ‘mse’ referenced before assignment

When I coded for mse and mae. Does anyone have seen this before?

[Code removed]

Thanks, Anthony

The error is telling you that you are using mse before it is actually defined. You are doing that when you calculate mse, that is not right. You might have gotten the names of the variables wrong. If you for example write mse1 =mse(…) and mse function is already defined then it would work. Also you shouldnt be posting solution code here.

I figured this out and now it works. Thanks.

Hi @gent.spah

I am having trouble with the function compute metrics

It works fine only for the first run of series_valid and naive_forecast

When I run it for the other metrics calculations, it produces the same (initial) values throughout

naive_forecast is done on the original series. So, make sure that series has not been modified when you try to do naive_forecast again.