GithubHelp home page GithubHelp logo

Comments (2)

sayanpatra avatar sayanpatra commented on June 22, 2024

Hi @vandonova,

You can retrieve the components for training as follows:

fig = result.model[-1].plot_components()  # Generates and stores the components
result.model[-1].silverkite_diagnostics.components

Currently there is no easy way to return the components for the forecasts, but it can be computed as follows.

Assumption: result is the output from the pipeline

import patsy

estimator = result.forecast.estimator
trained_model= estimator.model_dict
fut_df = result.forecast.df[["ts", "actual"]].rename(columns={"actual":"y"})

# Build Silverkite features
features_df_fut = estimator.silverkite._SilverkiteForecast__build_silverkite_features(
    df=fut_df,
    time_col=trained_model["time_col"],
    origin_for_time_vars=trained_model["origin_for_time_vars"],
    daily_event_df_dict=trained_model["daily_event_df_dict"],
    changepoint_values=trained_model["changepoint_values"],
    continuous_time_col=trained_model["continuous_time_col"],
    growth_func=trained_model["growth_func"],
    fs_func=trained_model["fs_func"],
    seasonality_changepoint_result=trained_model["seasonality_changepoint_result"],
    changepoint_dates=trained_model["trend_changepoint_dates"]
)

# Add autoregression terms
if trained_model["autoreg_func"] is not None:
    past_df = trained_model["df"].copy()
    df = pd.DataFrame({value_col: [np.nan]*fut_df.shape[0]})
    df.index = fut_df.index
    autoreg_df = estimator.silverkite._SilverkiteForecast__build_autoreg_features(
        df=df,
        value_col=trained_model["value_col"],
        autoreg_func=trained_model["autoreg_func"],
        phase="predict",
        past_df=past_df[[value_col]])
    features_df_fut = pd.concat(
        [features_df_fut, autoreg_df],
        axis=1,
        sort=False)

# Compute the design matrix
(x_mat_predict,) = patsy.build_design_matrices(
    [trained_model["x_design_info"]],
    data=features_df_fut,
    return_type="dataframe")

# Compute features df ( this is `x_mat_predict` multiplied by the training coefficients)
feature_df_predict = (trained_model["ml_model"].coef_* x_mat_predict)

# Calculate components
diagnostics = estimator.silverkite_diagnostics
components_predict = diagnostics.get_silverkite_components(
                fut_df,
                diagnostics.time_col,
                diagnostics.value_col,
                feature_df_predict)

Hope this helps. Have a good weekend.

from greykite.

vandonova avatar vandonova commented on June 22, 2024

Thanks @sayanpatra this is exactly what I needed.

from greykite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.