Main Content

Predict Battery State-Of-Charge Using Time Series Modeler App

This example shows how to train a multi-input single output autoregressive integrated moving average with extra input (ARIMAX) model using the Time Series Modeler app. You can use the workflow in this example to train autoregressive moving average (ARMA) models with different structures and training options.

The Time Series Modeler app trains models for time series modeling. For more information on the app, see Time Series Modeler (Deep Learning Toolbox).

Import and Preview Data in App

Load the data to import into the app. This example uses battery state-of-charge (SOC) data that contains the SOC as the output data (the response) and the current and temperature as the input data (the predictors).

load TSM_ARIMAX_data.mat

Set the random number seed for reproducibility.

rng(0)

Open the Time Series Modeler app.

timeSeriesModeler

To import data into the app, on the toolstrip, click New. The Import Data dialog box opens. Under the Data section, select Import responses and predictors from separate variables. Under Responses, select arimax_responses. Because the time steps in this data are in rows and the channels are in columns, select Use rows as time steps. Under Predictors, select arimax_predictors.

Under Validation, keep the default value of 20% in the Percentage of data to use for validation box.

Click Import.

Import Data dialog box

In the Data Set Summary section, verify that the data contains one response feature and two predictor features and that the app will split the data into 320 training and 80 validation time steps. The app displays the training and validation data plots for the responses and predictors in the Observation Preview pane.

Configure Model Structure

On the toolstrip, from the Models gallery, select ARMA Model. The Summary tab opens.

To configure the ARMA model as an ARIMAX model, in the Model Structure section, in the Configuration choice menu, click Specify orders. Set AR order (na), MA order (nc), and Input order (nb) to 1. Select Include integration. The ARIMAX model equation appears to the right of the options in the app. Keep the default values for the other options. For more information on the options available to configure the model structure, see Configure ARMA Model Structure and Training Options.

Summary tab in the app showing the model configuration options

Train Model

To train the ARIMAX model, on the toolstrip, click Train.

When the training completes, a plot displaying a set of candidate models and their respective normalized root mean squared error (NRMSE) values appears on the Model Selector tab. At the top of the plot, in the Metric menu, you can choose other quality metrics that you want the plot to display. The available quality metrics are RMSE, NRMSE, MAE, AIC, and BIC. If you select Metric as RMSE, NRMSE, or MAE, you can select Open-loop or Closed-loop at the top right of the plot to display the respective plots. To the left of the plot, in the Models section, you can choose all the models that you want to display. In the Datasets section, you can choose to display the Training dataset, Validation dataset, or both.

The plot automatically highlights and selects the model with the lowest NRMSE value on training data in the closed-loop metric setting.You can see the model information in the text box below the plot. You can select a different model by clicking the model in the plot or selecting it in the Select model list.

The qualities of the candidate models change based on the metric type and metric setting you choose. For a chosen metric, the candidate model with a lower metric value is better. When selecting a model, you can also weigh the value of the chosen metric against the complexity of the model.

For more information on model training and selection, see Train ARMA Model.

For this example, to finalize the model selected by the app and complete the training process, click Apply.

View the Training Results on the Summary tab.

Summary tab in the app showing the training results

Predict Values for Data

To predict values for the training and validation data using the selected model, on the toolstrip, click Predict. Set the Prediction type to Closed loop and Data source to Training. Set Response feature and Predictor feature to different values to view the corresponding response versus prediction plots. The predictions of the trained model match the true values well.

For more information on the available options, see Predict Values for Data.

Export Model

To export the trained model and generate code to predict new values for test data, on the toolstrip, click Export > Export to Workspace and Generate Code.

Export options in the app

A new variable, trainedModel_1, appears in the MATLAB® workspace. This variable is a structure containing the trained idpoly model. A new live script containing the generated code opens in the MATLAB editor.

See Also

Apps

Objects

Topics