Time-Series Prediction using ANFIS in MATLAB
Build a lagged time-series predictor with ANFIS in MATLAB, using five delays, a global ice-volume example, and a split that preserves stored order.

On this page
An implementation of ANFIS for nonlinear regression was shared earlier on Yarpiz: Nonlinear Regression using ANFIS. This post uses the same implementation for time-series forecasting. The time-series modeling task is converted into a function approximation problem, which ANFIS can solve.
The approach is used to build a model of the global ice volume and to predict it, based on data observed over the last 440,000 years.
From a time series to a regression problem
A time series is a sequence of values measured at equal time steps. A one step ahead prediction model estimates the next value from a few past values:
The past values are called lagged inputs, or delays. Each time step with gives one training sample: the inputs are the previous values and the target is . After this step, any regression method can learn . Here, is an ANFIS model.
In the code, the function CreateTimeSeriesData(x, Delays) builds these samples. With Delays = [1 2 3 4 5], each sample has five inputs, to .
The data
The file global_ice_volume.mat holds one time series of 219 values of the global ice volume, which covers the last 440,000 years. With five delays, it gives 214 samples. The same data is used in the post Time-Series Prediction using GMDH in MATLAB, so the two methods can be compared on the same problem.
The model
ANFIS (Jang, 1993) is a Takagi-Sugeno fuzzy system written as a five layer network. Each rule has the form “if the inputs are in these fuzzy sets, then the output is a linear function of the inputs”. Training uses hybrid learning: least squares for the linear consequents and gradient descent for the membership functions. The ANFIS regression post explains the structure in detail.
With five inputs, the choice of the initial FIS matters. Grid partitioning creates one rule for every combination of membership functions, so 2 membership functions per input already give rules. The clustering methods create one rule for each cluster, which keeps the model smaller.
How to run the code
Open the folder in MATLAB and run main.m. The script:
- loads the series and creates the lagged samples,
- splits the samples in time order: the first 75% for training and the last 25% for testing in the stored sequence,
- asks in dialog boxes for the FIS generation method and its parameters, and then for the training parameters,
- trains the FIS with
anfisand the hybrid method, - predicts all samples with
evalfisand computes the errors (MSE, RMSE, mean and standard deviation) for the training and test data, - plots the targets and outputs for the training, test and full data, and also draws regression plots when
plotregressionis available.
The default values in the dialogs are:
| Setting | Default |
|---|---|
Grid partitioning (genfis1) |
2 membership functions per input, gaussmf inputs, linear output |
Subtractive clustering (genfis2) |
influence radius 0.55 |
FCM (genfis3, the default method) |
10 clusters, exponent 2, 100 iterations, minimum improvement |
Training (anfis) |
100 epochs, error goal 0, initial step size 0.01, step size decrease rate 0.9, increase rate 1.1 |
The code uses the older Fuzzy Logic Toolbox functions genfis1, genfis2 and genfis3. Check the generation and training interfaces supported by your installed release. See the compatibility note in the ANFIS regression post.
To use your own series, replace x with a row vector of your data. You can also change Delays, for example to [1 2 3] for fewer inputs and a smaller rule base.
Check the result
Confirm the time direction and sampling interval of your source series before treating its stored order as chronological. Keep future observations out of training and preprocessing. These lagged samples evaluate one-step predictions using observed past values. Predicting several steps ahead by feeding predictions back into the model is a different experiment and can accumulate error. Compare with a simple persistence baseline and report error on the held-out segment rather than only on all samples together.
Applications
The same approach applies to many forecasting tasks, such as demand and load forecasting, financial and economic series, and environmental and hydrological data.
Downloads
How to cite
If you use this code or tutorial in your work, articles or publications, please cite it.
Mostapha Kalami Heris, Time-Series Prediction using ANFIS in MATLAB (YPFZ102), Yarpiz, 2015. https://yarpiz.com/time-series-prediction-using-anfis-ypfz102@misc{yarpiz-ypfz102,
author = {{Mostapha Kalami Heris}},
title = {{Time-Series Prediction using ANFIS in MATLAB}},
howpublished = {Yarpiz},
year = {2015},
note = {Code YPFZ102},
url = {https://yarpiz.com/time-series-prediction-using-anfis-ypfz102}
}Published Updated
Comments