wzhwzhwzh0921 / S-D-Mamba

Code for "Is Mamba Effective for Time Series Forecasting?"
137 stars 15 forks source link

How to use Mamba for forecasting #14

Open IsmailKhazi opened 2 months ago

IsmailKhazi commented 2 months ago

Hello can you provide a Python Notebook for "How to do forecasting using Mamba?"

How to use Mamba to forecast and compare with LSTM, RNN also.

wzhwzhwzh0921 commented 1 month ago

You can read Mamba's paper to learn the principles of Mamba Block. In fact, the input and output of Mamba Block are the same as those of classic RNN models such as LSTM and GRU. The input is the original tensor of the BLD shape, and the output is the hidden tensor (BLD Shape) corresponding to each position.

IsmailKhazi commented 1 month ago

But my code is related to bus arrival time which has both categorical and numerical features. Can you guide me how to do encoding for these. If needed I can share sample data for reference.

On Fri, 10 May, 2024, 4:48 pm wzhwzhwzh0921, @.***> wrote:

You can read Mamba's paper to learn the principles of Mamba Block. In fact, the input and output of Mamba Block are the same as those of classic RNN models such as LSTM and GRU. The input is the original tensor of the BLD shape, and the output is the hidden tensor (BLD Shape) corresponding to each position.

— Reply to this email directly, view it on GitHub https://github.com/wzhwzhwzh0921/S-D-Mamba/issues/14#issuecomment-2104430650, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH3Y25XMMSR2APAKKCTWIF3ZBSUHHAVCNFSM6AAAAABGJPGUW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBUGQZTANRVGA . You are receiving this because you authored the thread.Message ID: @.***>

TomKoester commented 1 month ago

An little example for forecasting in a notebook would be great @wzhwzhwzh0921

IsmailKhazi commented 1 month ago

I just want how to do encoding and train the model. As it is numerical data in a csv format. Can you guide me with that.

On Sun, 2 Jun, 2024, 9:01 pm Tom Koester, @.***> wrote:

An little example for forecasting in a notebook would be great @wzhwzhwzh0921 https://github.com/wzhwzhwzh0921

— Reply to this email directly, view it on GitHub https://github.com/wzhwzhwzh0921/S-D-Mamba/issues/14#issuecomment-2143900934, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH3Y25WIS7NEBVXLJACUXNTZFM3ELAVCNFSM6AAAAABGJPGUW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBTHEYDAOJTGQ . You are receiving this because you authored the thread.Message ID: @.***>

TomKoester commented 1 month ago

The data preproccesing for excatly this model i cant help. I just build an Prototype of the iTransformer model last week for TSA. For encode categorial data just encode it with numbers. If i get you problem right that would be something like bus:1 train:2 .... and after encoding you can normalize the data with sin/cos.

IsmailKhazi commented 3 weeks ago

Here is my data description

Name Description Data Type Example service_date Date on which the trip took place. Service dates run from around 2:00AM - 1:59:59AM Date 2019-12-31 route_id Route Id String 01 direction_id Identifies whether the trip is traveling inbound or outbound String Inbound half_trip_id Identification for the one way trip Integer 40836717 stop_id GTFS-compatible stop Integer 75 time_point_id The code for the timepoint String mit time_point_order The order of this timepoint in the trip Integer 4 point_type Identifies whether the stop is the starting point, midpoint, or endpoint for the trip String Midpoint standard_type Identifies whether the trip should be evaluated on the scheudle standard or headway standard. String Headway scheduled The time the trip was scheduled to depart the stop. The scheduled time should not be used to evaluated reliability if this trip is evaluated on the headway standard. Only the headway and run time should be used per the Service Delivery Policy. Time 12:30 AM actual The time the trip actually departed the timepoint. Time 12:29 AM scheduled_headway The scheduled time between the trip and the previous trip at the stop, in seconds. NULL if this trip is evaluated on the schedule standard. Integer 1200 headway The actual time between the trip and the previous trip at the stop, in seconds. NULL if this trip is evaluated on the schedule standard or if this is the last stop on the trip (endpoint). Endpoints are evaluated by whether the trip runtime is within 120% of the scheduled run time. Integer 1163

On Sun, 2 Jun, 2024, 10:04 pm Tom Koester, @.***> wrote:

The data preproccesing for excatly this model i cant help. I just build an Prototype of the iTransformer model last week for TSA. For encode categorial data just encode it with numbers. If i get you problem right that would be something like bus:1 train:2 .... and after encoding you can normalize the data with sin/cos.

— Reply to this email directly, view it on GitHub https://github.com/wzhwzhwzh0921/S-D-Mamba/issues/14#issuecomment-2143926146, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH3Y25QZKVAEI2TDTVNIL5DZFNCRJAVCNFSM6AAAAABGJPGUW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBTHEZDMMJUGY . You are receiving this because you authored the thread.Message ID: @.***>

ericleonardo commented 1 week ago

You can try Mambular (Mamba for Tabular data) new Python package ready to use:

https://github.com/basf/mamba-tabular

IsmailKhazi commented 1 week ago

Is it using Mamba concept under the hood

On Sun, 23 Jun, 2024, 2:52 am Eric Leonardo Cunha, @.***> wrote:

You can try Mambular (Mamba for Tabular data) new Python package ready to use:

https://github.com/basf/mamba-tabular

— Reply to this email directly, view it on GitHub https://github.com/wzhwzhwzh0921/S-D-Mamba/issues/14#issuecomment-2184193493, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH3Y25RD45CXUYZBRBMGSNDZIXTIHAVCNFSM6AAAAABGJPGUW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBUGE4TGNBZGM . You are receiving this because you authored the thread.Message ID: @.***>

ericleonardo commented 1 week ago

Yes, it is Mamba based. Take a look at the description and docs: https://mambular.readthedocs.io/

Mambular is a Python package that brings the power of Mamba architectures to tabular data, offering a suite of deep learning models for regression, classification, and distributional regression tasks. Designed with ease of use in mind, Mambular models adhere to scikit-learn's BaseEstimator interface, making them highly compatible with the familiar scikit-learn ecosystem. This means you can fit, predict, and evaluate using Mambular models just as you would with any traditional scikit-learn model, but with the added performance and flexibility of deep learning.

IsmailKhazi commented 1 week ago

In the github it is showing an example of Classification. But my use case is for Regression.

If possible can you make a simple example code snippet for Regression and Classification algorithm using Mamba

On Sun, 23 Jun, 2024, 8:43 am Eric Leonardo Cunha, @.***> wrote:

Yes, it is Mamba based. Take a look at the description and docs: https://mambular.readthedocs.io/

Mambular is a Python package that brings the power of Mamba architectures to tabular data, offering a suite of deep learning models for regression, classification, and distributional regression tasks. Designed with ease of use in mind, Mambular models adhere to scikit-learn's BaseEstimator interface, making them highly compatible with the familiar scikit-learn ecosystem. This means you can fit, predict, and evaluate using Mambular models just as you would with any traditional scikit-learn model, but with the added performance and flexibility of deep learning.

— Reply to this email directly, view it on GitHub https://github.com/wzhwzhwzh0921/S-D-Mamba/issues/14#issuecomment-2184410740, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH3Y25SIFGO3BGVC4BOED2TZIY4M3AVCNFSM6AAAAABGJPGUW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBUGQYTANZUGA . You are receiving this because you authored the thread.Message ID: @.***>

ericleonardo commented 1 week ago

Just read the docs. Regression:

https://mambular.readthedocs.io/en/latest/examples/regression.html

IsmailKhazi commented 1 week ago

Yeah I got that, My problem is more leaned to Time Series Forecasting. Can you give some suggestions on how to use it for time series.

On Sun, 23 Jun, 2024, 7:19 pm Eric Leonardo Cunha, @.***> wrote:

Just read the docs. Regression:

https://mambular.readthedocs.io/en/latest/examples/regression.html

— Reply to this email directly, view it on GitHub https://github.com/wzhwzhwzh0921/S-D-Mamba/issues/14#issuecomment-2184997479, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH3Y25WB7RFUBEOGF22BGWLZI3G6BAVCNFSM6AAAAABGJPGUW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBUHE4TONBXHE . You are receiving this because you authored the thread.Message ID: @.***>

ericleonardo commented 1 week ago

You can use the regression. In the train_test_split use shuffle=False to avoid leaking future samples in the training. Please, show how your data is structured. The description you sent above is confused because mixed columns. You can use print screen and paste here.

Name Description Data Type Example service_date Date on which the trip took place. Service dates run from around 2:00AM - 1:59:59AM Date 2019-12-31 route_id Route Id String 01

TomKoester commented 1 week ago

Is it also appliable for probalistic output to do multilabel classification? @ericleonardo

ericleonardo commented 1 week ago

Is it also appliable for probalistic output to do multilabel classification? @ericleonardo

You can try the Classification with multiclass output. In the example, it is used 4 classes: https://mambular.readthedocs.io/en/latest/examples/classification.html

Generate target variable: y = np.dot(X, coefficients) + np.random.randn(n_samples) Convert y to multiclass by categorizing into quartiles y = pd.qcut(y, 4, labels=False)

TomKoester commented 1 week ago

@ericleonardo Hey, thanks for the fast reply. I think you got me wrong there, i need an probalistic output for each class for a mutlilabel prediction. That means each input can be more than just one class. Example Input Class1 Class2 Class3 19.6.24 1 0 1

IsmailKhazi commented 1 week ago

Here is the link for the data description

https://mbta-massdot.opendata.arcgis.com/datasets/ef464a75666349f481353f16514c06d0/about

On Sun, 23 Jun, 2024, 8:22 pm Eric Leonardo Cunha, @.***> wrote:

You can use the regression. In the train_test_split use shuffle=False to avoid leaking future samples in the training. Please, show how your data is structured. The description you sent above is confused because mixed columns. You can use print screen and paste here.

Name Description Data Type Example service_date Date on which the trip took place. Service dates run from around 2:00AM - 1:59:59AM Date 2019-12-31 route_id Route Id String 01

— Reply to this email directly, view it on GitHub https://github.com/wzhwzhwzh0921/S-D-Mamba/issues/14#issuecomment-2185020704, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH3Y25QS2UMHD23XFY3C3ULZI3OJJAVCNFSM6AAAAABGJPGUW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBVGAZDANZQGQ . You are receiving this because you authored the thread.Message ID: @.***>

ericleonardo commented 1 week ago

@ericleonardo Hey, thanks for the fast reply. I think you got me wrong there, i need an probalistic output for each class for a mutlilabel prediction. That means each input can be more than just one class. Example Input Class1 Class2 Class3 19.6.24 1 0 1

I don't know if it will output class probabilities. You can ask the author: https://github.com/basf/mamba-tabular