Clear Filters
Clear Filters

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

54 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?

Answers (2)

Jacob Mathew
Jacob Mathew on 25 Sep 2024 at 3:35
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:
  3 Comments
Jacob Mathew
Jacob Mathew on 26 Sep 2024 at 4:57
You can compare the requirements of both Toolboxes at the link belo. There is dropdown where you can check the requirements for any Toolbox you may need to use as well:
In regards to creating the a model to predict 2 outputs, refer to the Time Series Forecasting example in Deep Learning Toolbox mentioned above. A snippet from the example shows that it has more than one output, which is suitable for your requirement:
翼
on 3 Oct 2024 at 8:46
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")

Sign in to comment.


Yifeng Tang
Yifeng Tang on 30 Sep 2024 at 23:52
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.
  4 Comments
翼
on 4 Oct 2024 at 1:07
Yes, my csv file is a time series data. The text is cut off in the left column in the attached image, though... Csv file has "time" column.
As I said in another chat of this post I'm mentioning someone, I was able to create LSTM model with DeepLearning Toolbox but I'm now having trouble exporting the model to Simulink block tha has 7 input signals and 2 output signals.
I'm stuck in that.
Thank you.
Yifeng Tang
Yifeng Tang on 4 Oct 2024 at 15:18
Are you able to save the "net" variable, which is the trained model, to a .mat file and share that file? I can take a look and see if there is a way to embed that into Simulink. I think it's do-able.

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!