Code Monkey home page Code Monkey logo

Comments (3)

jmoralez avatar jmoralez commented on June 17, 2024 1

In my opinion those APIs are more restrictive, since historic means "use a specific lag of these features" (output_chunk_length in darts and h in neuralforecast).

If you want to turn a feature into historic in mlforecast you can just use a lag that is longer than your forecasting horizon, for example:

import pandas as pd
from mlforecast import MLForecast
from mlforecast.utils import generate_series, generate_prices_for_series
from sklearn.linear_model import LinearRegression

# generate data. the prices span the full range of training dates (so it's a future exog)
series = generate_series(2, equal_ends=True)
prices = generate_prices_for_series(series, horizon=0)

# turn to historic
prices_lag5 = prices.rename(columns={'price': 'price_lag5'})
prices_lag5['ds'] += 5 * pd.offsets.Day()
prices_lag10 = prices.rename(columns={'price': 'price_lag10'})
prices_lag10['ds'] += 10 * pd.offsets.Day()
historic_prices = prices_lag5.merge(prices_lag10, on=['unique_id', 'ds'])

# merge with training set. this drops some rows but if you have more history you wouldn't need to
train = series.merge(historic_prices, on=['unique_id', 'ds'])

# use the regular API for training and forecasting
mlf = MLForecast(
    models=[LinearRegression()],
    freq='D',
)
mlf.fit(train, static_features=[])
mlf.predict(h=5, X_df=historic_prices)

Since h=5 here we can use any lag>=5 as "historic" (5 and 10 in this example).

This doesn't seem that hard. It would be harder to add a new argument to determine which lag to take, a new argument to provide the historic features, etc.

from mlforecast.

Vitorbnc avatar Vitorbnc commented on June 17, 2024 1

Thanks @jmoralez! I will close this as the procedure seems simple enough. We may reopen later if needed.

from mlforecast.

kkckk1110 avatar kkckk1110 commented on June 17, 2024

I have the same question. Can I construct the features before training and hence I can incorporate those features into feature engineering process.

from mlforecast.

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.