This is a Theano implementation of our work Developing a Long Short-Term Memory (LSTM) based Model for Predicting Water Table Depth in Agricultural Areas. [Paper]
NEW: PyTorch implementation also available: Water-Table-Depth-Prediction-PyTorch!
Python3.x(Tested with 3.5)
theano(Tested with 1.0.1)
numpy
pandas
scikit-learn
The code was tested with Python 3.5. To use this code, please do:
-
Clone the repo:
git clone https://github.com/jfzhang95/LSTM-water-table-depth-prediction.git cd LSTM-water-table-depth-prediction
-
Install dependencies:
pip install theano matplotlib numpy pandas scikit-learn
-
To try the demo code, please run:
python demo.py
If installed correctly, the result should look like this:
Noted that the demo data (demo.csv) are processed manually, so they are not real data, but they still can reflect the correlation between the original data.
A model training and testing pipeline can be defined as:
def LSTM_FC_prediction(X, Y, X_test=None, iters=20000, learning_rate=1e-4, dropout_prob=0.5):
if dropout_prob > 1. or dropout_prob < 0.:
raise Exception('Dropout level must be in interval [0, 1]')
num_month = Y.shape[0]
input_shathinkpe = X.shape[1]
model = LSTM_FC_Model(num_input=input_shape, num_hidden=[40], num_output=1)
print('Start training......')
for iter in range(iters + 1):
loss = model.fit(X, Y, learning_rate, dropout_prob)
if iter % 1000 == 0:
print("iteration: %s, loss: %s" % (iter, loss))
# Saving model
model.save_model_params('checkpoints/LSTM_FC_CKPT')
print('Start predicting......')
Y_test = model.predict(X_test)
print('Done.')
return Y_test
For more details, please see in tuitorials.
If you use this code, please consider citing the following paper:
@article{zjf18,
journal = {Journal of Hydrology},
title = {Developing a Long Short-Term Memory (LSTM) based Model for Predicting Water Table Depth in Agricultural Areas},
author = {Jianfeng Zhang, Yan Zhu, Xiaoping Zhang, Ming Ye and Jinzhong Yang},
year = {2018},
volume = {561},
pages = {918-929}
}