Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not understanding the prediction results for the example application #4

Open
wilbertmatthew opened this issue Jun 2, 2024 · 5 comments

Comments

@wilbertmatthew
Copy link

Hi,

When I run the example application I do not understand the prediction results. The test data and prediction results are the same. I was looking for the prediction results array to have some of values greater for steps ahead than the test array. Listed are the test, prediction and x_test_pred arrays after the application run for 28 steps ahead prediction.

Thanks

Wilbert Jackson

/home/wilbert/PyPSF/pypsf/psf.py:149:UserWarning:
Prediction horizon 28 is not multiple of 12. Using 36 as intermediate prediction horizon!
pred [[404]
[359]
[310]
[337]
[360]
[342]
[406]
[396]
[420]
[472]
[548]
[559]
[463]
[407]
[362]
[405]
[417]
[391]
[419]
[461]
[472]
[535]
[622]
[606]
[508]
[461]
[390]
[432]]
test [[404]
[359]
[310]
[337]
[360]
[342]
[406]
[396]
[420]
[472]
[548]
[559]
[463]
[407]
[362]
[405]
[417]
[391]
[419]
[461]
[472]
[535]
[622]
[606]
[508]
[461]
[390]
[432]]
x_test_pred [115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
133 134 135 136 137 138 139 140 141 142]

@mamei16
Copy link
Owner

mamei16 commented Jun 2, 2024

Hi,
Unfortunately, I can't reproduce this issue on my end. My pred array contains the following values:
[427.5, 370.5, 329.5, 364., 371.5, 348.5, 399.5, 396., 404., 473., 539., 547., 467.3, 403.9, 357.9, 392., 397.9, 369.9, 421.3, 413.8, 425.8, 509.2, 578.2, 591.4, 490.8, 427.4, 382.4, 420.]

Could you provide the python version you're using, as well as the versions of scikit-learn and numpy, respectively? I'm not sure what the issue could be, so I want to try to reproduce the issue on my machine as a start.

@wilbertmatthew
Copy link
Author

Thank you for your quick response. Here are the versions you requested.

python3 --version
Python 3.11.7

print('The numpy version is {}.'.format(np.version))
The numpy version is 1.26.4.

print('The scikit-learn version is {}.'.format(sklearn.version))
The scikit-learn version is 1.2.2.

@wilbertmatthew
Copy link
Author

Hi,

It is working now. I made no changes to the example I just ran it with different step ahead values and noticed it started working.

Several questions:

  1. How to fix the warnig. /home/wilbert/PyPSF/pypsf/psf.py:149:UserWarning:
    Prediction horizon 18 is not multiple of 12. Using 24 as intermediate prediction horizon!

  2. When I run with step ahead other than set at 28 the prediction/test plots are off. I ran 12, 50, 10, 30. Plots are attached.

Code used
import numpy as np
import matplotlib.pyplot as plt
from pypsf import Psf

plt.style.use("dark_background")

t_series = np.array([112, 118, 132, 129, 121, 135, 148, 148, 136, 119, 104, 118,
115, 126, 141, 135, 125, 149, 170, 170, 158, 133, 114, 140,
145, 150, 178, 163, 172, 178, 199, 199, 184, 162, 146, 166,
171, 180, 193, 181, 183, 218, 230, 242, 209, 191, 172, 194,
196, 196, 236, 235, 229, 243, 264, 272, 237, 211, 180, 201,
204, 188, 235, 227, 234, 264, 302, 293, 259, 229, 203, 229,
242, 233, 267, 269, 270, 315, 364, 347, 312, 274, 237, 278,
284, 277, 317, 313, 318, 374, 413, 405, 355, 306, 271, 306,
315, 301, 356, 348, 355, 422, 465, 467, 404, 347, 305, 336,
340, 318, 362, 348, 363, 435, 491, 505, 404, 359, 310, 337,
360, 342, 406, 396, 420, 472, 548, 559, 463, 407, 362, 405,
417, 391, 419, 461, 472, 535, 622, 606, 508, 461, 390, 432])
train = t_series[:-28]
#test = t_series[-28:]
#test = t_series[-12:]
#test = t_series[-50:]
#test = t_series[-10:]
test = t_series[-30:]

psf = Psf(cycle_length=12, apply_diff=True, diff_periods=12)
psf.fit(train)

pred = psf.predict(len(test))

fig, ax = plt.subplots()
x_train = np.array(range(len(train)))
x_test_pred = np.array(range(len(test))) + x_train[-1]
ax.plot(x_train, train, c="lightblue")
ax.plot(x_test_pred, test, c="lightgreen")
ax.plot(x_test_pred, pred, c="tab:orange")
plt.legend(["Training", "Test- steps ahead 28", "Prediction"])
plt.tight_layout()

print("test", test)
#print("test.shape", test.shape)
print("")
print("pred", pred)
#print("pred.shape", pred.shape)

plt.show()

Plots
28stepsahead
50stepsahead
12stepsahead
10stepsahead
30stepsahead

Thanks

@wilbertmatthew
Copy link
Author

Forgot to include the prediction log data.

28 steps ahead
test [404 359 310 337 360 342 406 396 420 472 548 559 463 407 362 405 417 391
419 461 472 535 622 606 508 461 390 432]

pred [427.5 370.5 329.5 364. 371.5 348.5 399.5 396. 404. 473. 539. 547.
467.3 403.9 357.9 392. 397.9 369.9 421.3 413.8 425.8 509.2 578.2 591.4
490.8 427.4 382.4 420. ]

12 steps ahead
test [417 391 419 461 472 535 622 606 508 461 390 432]

pred [427.5 370.5 329.5 364. 371.5 348.5 399.5 396. 404. 473. 539. 547. ]

50 steps ahead
test [271 306 315 301 356 348 355 422 465 467 404 347 305 336 340 318 362 348
363 435 491 505 404 359 310 337 360 342 406 396 420 472 548 559 463 407
362 405 417 391 419 461 472 535 622 606 508 461 390 432]

pred [427.5 370.5 329.5 364. 371.5 348.5 399.5 396. 404. 473. 539. 547.
467.3 403.9 357.9 392. 397.9 369.9 421.3 413.8 425.8 509.2 578.2 591.4
490.8 427.4 382.4 420. 429.4 400.4 458.8 461.8 466.8 547.2 626.2 633.4
530.6 460.8 410.8 448. 455.8 421.8 480.6 479.6 488.6 583.4 665.4 677.8
554.1 484.3]

10 steps ahead
test [419 461 472 535 622 606 508 461 390 432]

pred [427.5 370.5 329.5 364. 371.5 348.5 399.5 396. 404. 473. ]

30 steps ahead
test [491 505 404 359 310 337 360 342 406 396 420 472 548 559 463 407 362 405
417 391 419 461 472 535 622 606 508 461 390 432]

pred [427.5 370.5 329.5 364. 371.5 348.5 399.5 396. 404. 473. 539. 547.
467.3 403.9 357.9 392. 397.9 369.9 421.3 413.8 425.8 509.2 578.2 591.4
490.8 427.4 382.4 420. 429.4 400.4]

@mamei16
Copy link
Owner

mamei16 commented Jun 3, 2024

Great to hear you made it work!

Regarding your questions:

  1. The only way to remove this warning is to set the length of the prediction horizon to a number that is a multiple of the cycle length. The PSF algorithm produces c predicted values per iteration, where c is the cycle length.
  2. When you change the number of values to predict, you also need to change the size of the test set accordingly, for the plots to display correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants