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

Issues that occur when loading model files #2527

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

donggu-kang
Copy link

Hi. The issue below appears to occur when the Prophet model loads an existing trained model on time series data with constant values (e.g. a single value of 1).

An error occurs when loading the model using the original code block below. The same error occurs in experiments such as unit func(1) and unit func(10).

def warm_start_params(m):
    res = {}
    for pname in ['k', 'm', 'sigma_obs']:
        if m.mcmc_samples == 0:
            res[pname] = m.params[pname][0][0]
        else:
            res[pname] = np.mean(m.params[pname])
    for pname in ['delta', 'beta']:
        if m.mcmc_samples == 0:
            res[pname] = m.params[pname][0]
        else:
            res[pname] = np.mean(m.params[pname], axis=0)
    return res
2023-11-13 17:57:52,173 - [CRITICAL] - **********:250 - ERROR - invalid index to scalar variable.
2023-11-13 17:57:52,173 - [CRITICAL] - **********:251 - Traceback (most recent call last):
  File "**********.py", line 204, in **********
    ********** = adf.AdfForeWorker(tag_id=tag_id,
  File "**********.py", line 486, in **********
    warm_start_params(m)
  File "**********.py", line 476, in warm_start_params
    res[pname] = m.params[pname][0][0]
IndexError: invalid index to scalar variable.

If a single value is used for model fitting as shown above, the Prophet model cannot learn the various statistical variabilities required for prediction. Therefore, some parameters may be set differently than expected.

Personally, I think this is what's causing the IndexError in the warm_start_params function.

That is, when a model is trained on constant-valued (non-volatile) data, some parameters may be set to scalar values or arrays of lower dimension than expected. (The above exception occurs if the expected value is a two-dimensional array, but is actually a one-dimensional array.)

This means that learning from data that only has constant values may result in some parameters (e.g. trend point (delta), seasonal component (beta)) being set differently than expected.

This means that the parameter can be set to a single value or an array of lower dimensions than expected.

Even if it is saved as a low-dimensional array, the model should be able to be loaded without error.

I registered this PR to update the above code to the official documentation.

Thank you always for creating Prophet.

@facebook-github-bot
Copy link
Contributor

Hi @donggu-kang!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@donggu-kang
Copy link
Author

#2072 (comment)

@donggu-kang donggu-kang changed the title Improved issues when loading model files Issues that occur when loading model files Nov 14, 2023
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@tcuongd
Copy link
Collaborator

tcuongd commented May 18, 2024

When there's a constant value series, does the model fit actually succeed? I'm wondering if the values in .params are just the prior values. And if the model fit doesn't succeed / it's not a good model, I'm not sure why people would want to use it as a warm start.

Thanks for catching the out of index error. But I think I'd rather catch those cases and raise an error (e.g. model used for warm start does not have properly fitted parameters). It's a better user experience imo than through passing the old parameters, which won't hold much information or won't give any advantages to fitting the new model.

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

Successfully merging this pull request may close these issues.

None yet

4 participants