Giter VIP home page Giter VIP logo

Comments (5)

Axemen avatar Axemen commented on August 28, 2024 1

Hey @young-hun-jo,

The Vector Auto-Regression (VAR) model is designed to take multiple inputs and produce multiple outputs.

It follows the traditional Auto-Regression (AR) model's formula while replacing the individual weights and lags with matrices instead.

You can read more about the math itself here on wikipedia.

As for other models in KATS that can perform multi-variate regression with a singular output, luckily some can. However, it may not be in a format that you are used to (I know it wasn't for me the first time I saw it).

For some models KATS supports you can use the endogenous and exogenous variables.

Where endogenous (endog) is the historical data from the time series you are trying to predict.

And the exogenous (exog) is a second independent variable that has some effect on the endogenous variable.

A better explanation of endog and exog variables

Here's an example of using the ARIMA model with an exogenous variable as well.

df = pd.read_csv("../data/air_passengers.csv", parse_dates=True, infer_datetime_format=True, index_col='ds')

# Setting the exogenous variable to be the month of the year.
exog = df.index.month.values

# Creating the ts 
air_ts = TimeSeriesData(time=df.index, value=df.y)

# Setting the exogneous variable in the model params
params = ARIMAParams(2, 1, 1, exog=exog, freq='MS')

model = ARIMAModel(air_ts, params)
model.fit()

# Note that exogenous variables are required to make the forecast so we have to calculate the exog again for forecasting 
steps = 5
start = exog[-1]

# Generating the next months for the forecast, starting from the last month 
fcst_exog = np.array([(i % 12 + 1) for i in range(start, start+steps)])

model.predict(5, exog=fcst_exog)

from kats.

Axemen avatar Axemen commented on August 28, 2024 1

You absolutely can have multiple variables in your exog argument!

I modified the example to include multiple arguments here

df = pd.read_csv("../data/air_passengers.csv", parse_dates=True, infer_datetime_format=True, index_col='ds')

exog = pd.DataFrame({
    "month": df.index.month,
    "year": df.index.year
}).values

# Creating the ts 
air_ts = TimeSeriesData(time=df.index, value=df.y)

# Setting the exogneous variable in the model params
params = ARIMAParams(2, 1, 1, exog=exog, freq='MS')

model = ARIMAModel(air_ts, params)
model.fit()

# Note that exogenous variables are required to make the forecast so we have to calculate the exog again for the forecasting steps
steps = 5
start = exog[-1]

fcst_exog = pd.DataFrame({
    "month": [(i % 12 + 1) for i in range(start[0], start[0]+steps)],
    "year": list(range(start[1], start[1]+steps))
}).values

model.predict(5, exog=fcst_exog)

from kats.

Axemen avatar Axemen commented on August 28, 2024 1

The key is to make sure that the exog variable is a numpy array with the shape (length_of_data, number_of_variables).

In this example the length of the training data is 144 and the number of exog variables is 2 so the shape for exog needs to be (144, 2)

from kats.

young-hun-jo avatar young-hun-jo commented on August 28, 2024 1

Thanks for your awesome explanation and example! I could do this due to you! I will close this issue 😆

from kats.

young-hun-jo avatar young-hun-jo commented on August 28, 2024

Thanks for explaining this! You provided me the example with one exogenous variable. But my data has two more than exogenous variables. Can I input more exogenous variables into exog argument? If I can do this, how can I set a type of more exogenous variable? (e.g list -> exog=[exog1, exog2, exog3, ... ])

from kats.

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.