LibCity / Bigscity-LibCity

LibCity: An Open Library for Urban Spatial-temporal Data Mining
https://libcity.ai/
Apache License 2.0
922 stars 168 forks source link

How to predict a new sample (1 sample) on existing model? #316

Closed TienNguyenKha closed 1 year ago

TienNguyenKha commented 2 years ago

Hi, thank for your contribution you have made. I wonder if i could use trained model to predict on a new sample ? Can you give me instructions or code demo? ( Now I'm using ACFM model for traffic flow prediction task. )

aptx1231 commented 2 years ago

Do you mean prediction with a trained model? You need to specify two parameters, one is --train False, which controls the code to test directly without training. The other is --exp_id ID. ID is an exp_id randomly generated when training the model. The trained model should be stored in the directory libcity/cache/ID/model_cache, so you need to specify the ID.

aptx1231 commented 2 years ago

What does "1 sample" mean?

TienNguyenKha commented 2 years ago

What does "1 sample" mean?

I'm using ACFM model for traffic flow prediction task. And I trained it with "NYCTAXI201401-201403_GRID" dataset. I saw the length of 1 input sequence is 6 and the output is 1. How can I predict with another new sequence? I don't know how to preprocessing new raw data to model's input and which code to call and predict this new sequence.

aptx1231 commented 2 years ago

Modify the parameters input_window and output_window to change the length of input and output.

aptx1231 commented 2 years ago

Do you mean prediction with a trained model? You need to specify two parameters, one is --train False, which controls the code to test directly without training. The other is --exp_id ID. ID is an exp_id randomly generated when training the model. The trained model should be stored in the directory libcity/cache/ID/model_cache, so you need to specify the ID.

This is all that is needed to make predictions with the trained model, no data processing is required.

TienNguyenKha commented 2 years ago

I keep the input_window and output_window like you. I mean, If I have new sequence (,=not in train/val/test). Which code I need to use in this case to predict?

aptx1231 commented 2 years ago

This requires processing the data into atomic files before libcity can be used.

TienNguyenKha commented 2 years ago

Assume I had atomic files, which code can I use ?

aptx1231 commented 2 years ago

You can run the model directly with run_model.py, --train false and --exp_id ID to specify the location of the pre-trained model to apply the pre-trained model to the new data.

TienNguyenKha commented 2 years ago

Can I run "test_model.py" to test? I trained AFCM model with id=28778. Have I configured it properly to load this model ? git_libcity

aptx1231 commented 2 years ago

test_model.py only takes a batch data for testing, it can't achieve your requirement

B046090010 commented 1 year ago

Hello, I have a similar problem. If we only have the value of X, how do we make the inference of y using the existing model? Thanks a lot.

aptx1231 commented 1 year ago

You can run the model directly with run_model.py, --train false and --exp_id ID to specify the location of the pre-trained model to apply the pre-trained model to the new data.

In this case, a pre-trained model is needed first. You can use other datasets to train the model in Libcity and generate a exp_id when training. Then, you can run the model directly with run_model.py, --train false and --exp_id ID to specify the location of the pre-trained model to apply the pre-trained model to the new data X.

B046090010 commented 1 year ago

You can run the model directly with run_model.py, --train false and --exp_id ID to specify the location of the pre-trained model to apply the pre-trained model to the new data.

Thank you for your response. Is the implementation steps as follows.

Suppose I have finished training DMVST with NYCTaxi20150103 dataset, then when I want to predict future data, e.g., taxi demand after 2015/3/1.

I need to modify NYCTaxi20150103.grid to add the data after 2015/03/01, and set departing_volume and arriving_volume to 0.

Finally, use run_model to adjust the test_rate to get the predicted value after multiple steps.

aptx1231 commented 1 year ago

You can run the model directly with run_model.py, --train false and --exp_id ID to specify the location of the pre-trained model to apply the pre-trained model to the new data.

Thank you for your response. Is the implementation steps as follows.

Suppose I have finished training DMVST with NYCTaxi20150103 dataset, then when I want to predict future data, e.g., taxi demand after 2015/3/1.

I need to modify NYCTaxi20150103.grid to add the data after 2015/03/01, and set departing_volume and arriving_volume to 0.

Finally, use run_model to adjust the test_rate to get the predicted value after multiple steps.

Yes, after you have trained DMVSTNET, just set --train false and the appropriate test_rate to make predictions only on this part of the test set. Thank you for the detailed steps.