Is it possible to make Machine Learning model to predict multiple outputs with Statistics and Machine Learning Toolbox?

18 views (last 30 days)
I'd like to create a model to predict two output signals based on the following seven input signals, by using Statistics and Machine Learning Toolbox.
This csv is a the data (about 4,200 rows) used as training data.
This data is a time series every 0.025 seconds.
I think the model type is Regressin model if you create a model from this data.
(Data type of each Signal is double type.)
Input Signals:
  • V_TGT_Vehicle
  • P_DCDC_PNT_W
  • P_HVAC_PNT_W
  • SOC_BT_Hi_PNT_per
  • open_accel_Driver_per
  • open_break_Driver_per
  • w_MG_PNT_radps
Output Signals:
  • trq_MG2_tgtCalc1
  • trq_MG2_tgtCalc2
I've been going through Statistics and Machine Learning Toolbox documentation, I'm not sure if it's possible to create a machine learning model like above.
I'd like to export the model as Simulink block.
Do you have any ideas?
How do I make this with Statistics and Machine Learning Toolbox?

Accepted Answer

Yifeng Tang
Yifeng Tang on 30 Sep 2024
Using Regression Learner App, you can build a regression model for EACH of the outputs. That is to say you need to build TWO models. The app support saving the resulting regression model for use in Simulink for newer versions. Looks like you are using R2024b, so it should be OK.
Here is an example of brining one regression model to Simulink: https://www.mathworks.com/help/stats/predict-responses-using-regression-gp-predict-block.html. You just need to use two of this.
Here are examples of similar workflow for other types of models: https://www.mathworks.com/help/stats/examples.html?category=code-generation&s_tid=CRUX_topnav
You can also do this using MATLAB Function in Simulink. Here is an example: https://www.mathworks.com/help/stats/predict-class-labels-using-matlab-function-block.html. The class label model can be replaced with any regression model. You can modify the MATLAB function to accept multiple regression models and produce multiple outputs. However, each regression model is multi-input-single-output.
  8 Comments
Yifeng Tang
Yifeng Tang on 7 Oct 2024
Also, you may check out the Step 6 and 7 from this example: Battery State of Charge Estimation Using Deep Learning. Once you export your trained network to a format for Simulink using "exportNetworkToSimulink(recurrentNet)", it can be used in Simulink using a "Predict" block.

Sign in to comment.

More Answers (1)

Jacob Mathew
Jacob Mathew on 25 Sep 2024
Hey 翼,
The Statistics and Machine Learning Toolbox deals with classical machine learning models like linear regression and decision tree ensemble approaches which deal with a single output. If there are any data preprocessing or transformation which allows single parameter output for the dataset then the following examples are worth exploring:
However, if you have require the output to have two signals, then you will require the Deep Learning Toolbox to create regression neural networks. The link to the Toolbox is :
Refer to the following example to get started with Time Series Forecasting:
Once the model has been trained, it can be exported using the exportNetworkToSimulink function. The link to the function’s documentation is below:
  4 Comments
翼
on 3 Oct 2024
Much Appreciated.
I tried Deep Learning Toolbox and used exportNetworkToSimulink function, however it didn't work..
I got this error,
The argument at position 1 is invalid. Value must be of type dlnetwork or convertible to dlnetwork.
I'm not quite sure what exactly the error says....
Do you happen to know this ? How do I modify?
Here is my MATLAB code.
I want to create a model and export it to Simulink as Block that has 7 input signals and 2 output signals.
data = readtable('data.csv');
inputVariables = {'v_VL_PNT_mps_1', 'w_MG_PNT_radps', 'open_brake_Driver_per', ...
'open_accel_Driver_per', 'SOC_BT_Hi_PNT_per', 'P_HVAC_PNT_W', 'P_DCDC_PNT_W'};
XTrain = table2array(data(:, inputVariables));
outputVariables = {'F_VCU_CNT_re_break_N', 'tgt_Trq_VCU_CNT_MG_Nm'};
YTrain = table2array(data(:, outputVariables));
inputSize = numel(inputVariables);
outputSize = numel(outputVariables);
layers = [
featureInputLayer(inputSize)
fullyConnectedLayer(10)
reluLayer
fullyConnectedLayer(outputSize)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs', 100, ...
'Plots', 'training-progress', ...
'Verbose', 0);
net = trainNetwork(XTrain, YTrain, layers, options);
exportNetworkToSimulink(net,ModelName="myExportedModel")
Philip Brown
Philip Brown on 23 Oct 2024
exportNetworkToSimulink works on networks of type dlnetwork, but trainNetwork trains a DAGNetwork network.
To train dlnetwork objects, you could take a look at the trainnet function.However, a simple workaround for you may be to call dlnet = dag2dlnetwork(net), which will convert the network type.

Sign in to comment.

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!