Skip to content

Welcome to AI4Water

For code visit github.


A uniform and simplified framework for rapid expermenting with deep leanring and machine learning based models for time series and structured data.

The specific purposes of the repository are

  • compliment the functionality of keras/pytorch/sklearn by making pre and post processing easeier for time-series prediction/classification problems (also holds true for any 1D data).

  • save, load/reload or build models from readable json file. This repository provides a framework to build layered models using python dictionary and with several helper tools which fasten the process of modeling time-series forcasting.

  • provide a uniform interface for optimizing hyper-parameters for skopt; sklearn based grid and random; hyperopt based tpe, atpe or optuna based tpe, cmaes etc. See example
    using its application.

  • cut short the time to write boiler plate code in developing machine learning based models.

  • It should be possible to overwrite/customize any of the functionality of the AI4Water's Model by subclassing the Model. So at the highest level you just need to initiate the Model, and then need fit, predict and view_model methods of Model class but you can go as low as you could go with tensorflow/keras.

  • All of the above functionalities should be available without complicating keras implementation.


using github link

python -m pip install git+

using setup file, go to folder where repo is downloaded

python install

The latest code however (possibly with less bugs and more features) can be insalled from dev branch instead

python -m pip install git+

To install the latest branch (dev) with all requirements use the following command

python -m pip install "AI4Water[all] @ git+"

How to use

Build a Model by providing all the arguments to initiate it.

from ai4water import Model
from ai4ater.datasets import arg_beach
data = arg_beach()
model = Model(
        model = {'layers': {"LSTM": 64}},
        data = data,
        input_features=['tide_cm', 'wat_temp_c', 'sal_psu', 'air_temp_c', 'pcp_mm'],   # columns in csv file to be used as input
        output_features = ['tetx_coppml'],     # columns in csv file to be used as output
        lookback = 12

Train the model by calling the fit() method

history =

Make predictions from it

true, predicted = model.predict()

Using your own pre-processed data

You can use your own pre-processed data without using any of pre-processing tools of AI4Water. You will need to provide input output paris to data argument to fit and/or predict methods.

import numpy as np
from ai4water import Model  # import any of the above model

batch_size = 16
lookback = 15
inputs = ['dummy1', 'dummy2', 'dummy3', 'dumm4', 'dummy5']  # just dummy names for plotting and saving results.

model = Model(
            model = {'layers': {"LSTM": 64,
                                'Dense': 1}},
x = np.random.random((batch_size*10, lookback, len(inputs)))
y = np.random.random((batch_size*10, len(outputs)))

history =,y=y)

using for scikit-learn/xgboost/lgbm/catboost based models

The repository can also be used for machine learning based models such as scikit-learn/xgboost based models for both classification and regression problems by making use of model keyword arguments in Model function. However, integration of ML based models is not complete yet.

from ai4water import Model
from ai4water.datasets import arg_beach

data = arg_beach()  # path for data file

model = Model(
        input_features=['tide_cm', 'wat_temp_c', 'sal_psu', 'air_temp_c', 'pcp_mm'],   # columns in csv file to be used as input
        output_features = ['tetx_coppml'],  
        #  any regressor from
        model={"randomforestregressor": {"n_estimators":1000}},  # set any of regressor's parameters. e.g. for RandomForestRegressor above used,
    # some of the paramters are

history =

preds, obs = model.predict()