How to fix AttributeError: 'Prophet' object has no attribute 'scaling' in Azure ML studio notebook

Prakatheeswari 20 Reputation points
2024-05-15T21:57:23.9166667+00:00

I have trained a time series model using automated ml. I registered that model and deployed it. Then I am calling the model using pickle file and trying to make prediction for test data. My time series model includes Prophet algorithm and I am getting the following error while making prediction.

AttributeError: 'Prophet' object has no attribute 'scaling'

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,642 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,486 questions
{count} votes

Accepted answer
  1. dupammi 7,745 Reputation points Microsoft Vendor
    2024-05-16T03:25:47.53+00:00

    Hi @Prakatheeswari

    Thank you for using the Microsoft Q&A forum.

    It appears that the scaling attribute exists and can be accessed without an error. However, you mentioned that you encountered the AttributeError: 'Prophet' object has no attribute 'scaling' while making predictions in another context.

    I tried the following from the Azure ML Notebook cell and followed the below troubleshooting steps.

    %pip install Prophet 
    

    This worked for me.

    You please try below troubleshooting steps.

    1. Ensure that the version of prophet (or fbprophet if using an older version) in both the training and prediction environments are the same. Differences in library versions can result in missing attributes.
         import prophet
         print(prophet.__version__)
      
    2. If there is a mismatch, install the correct version using:
         pip install prophet=={version_number}
      
    3. If the issue is due to old version, try upgrading the prophet package by running the following command:
          !pip install --upgrade fbprophet
      
    4. Attribute Check: Double-check the attribute access in your deployment code to ensure that it's correct and not misspelled or referenced incorrectly. As part of troubleshooting, try printing the all the attributes, to see if scaling is one among those attributes.
    5. Recreate the Issue in a Controlled Environment. Try to replicate the error in a new environment using the same versions and steps as in Azure ML. This helps isolate if the issue is specific to the Azure environment.

    Below is the troubleshooting script I used and tried to also print all the attributes.

    # Import necessary libraries
    import pandas as pd
    import numpy as np
    from prophet import Prophet
    import matplotlib.pyplot as plt
    import pickle
    
    # Ensure inline plotting
    %matplotlib inline 
    
    # Set plot style
    plt.rcParams['figure.figsize'] = (20, 10)
    plt.style.use('ggplot')
    
    # Example data (you should replace this with your actual data loading)
    dates = pd.date_range(start='2022-01-01', periods=100)
    data = np.random.randn(100).cumsum()
    df = pd.DataFrame({'ds': dates, 'y': data})
    
    # Check Prophet version
    import prophet
    print(f"Prophet version: {prophet.__version__}")
    
    # Fit the Prophet model
    model = Prophet()
    model.fit(df)
    
    # Save the model to a pickle file
    with open('prophet_model.pkl', 'wb') as f:
        pickle.dump(model, f)
    
    # Load the model from the pickle file
    with open('prophet_model.pkl', 'rb') as f:
        loaded_model = pickle.load(f)
    
    # Check if the scaling attribute exists and print it
    try:
        print("Accessing 'scaling' attribute:")
        scaling_value = loaded_model.scaling
        print(f"Scaling value: {scaling_value}")
    except AttributeError as e:
        print(f"Error accessing 'scaling' attribute: {e}")
    
    # Attempt to make a prediction
    try:
        future = loaded_model.make_future_dataframe(periods=30)
        forecast = loaded_model.predict(future)
        
        # Plot the forecast
        fig = loaded_model.plot(forecast)
        plt.show()
        
        # Plot forecast components
        fig_components = loaded_model.plot_components(forecast)
        plt.show()
    
    except AttributeError as e:
        print(f"Error during prediction: {e}")
    
    # Check attributes of the loaded model (for debugging)
    print("Loaded model attributes:")
    print(dir(loaded_model))
    
    

    Output Printed:User's image

    User's image

    I hope this helps you further in troubleshooting the error you were encountering and to fix it.

    Thank you.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful