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

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?

 Respuesta aceptada

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 comentarios

Is it possible to train the attached CSV data with DeepLearningToolbox and export to Simulink as Block.
I mean, I want to create the machine learning model use 7 input signals and predict 2 output signals.
It'd b nice if you could tell me how to do this.
Best,
Hi @翼,
I noticed in your original question, the cvs file appears to be a time series data. Is that correct? If so, the regression and neural network models from Statistics and Machine Learning Toolbox may not be sufficient, as those are usually input-output type, best suited for steady-state points. You may need things like LSTM type model (Deep Learning Toolbox), or Neural State-Space model (System Identification Toolbox).
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.
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.
Sorry for the late reply, Thank you.
data = readtable('soc_10.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);
if isa(net, 'SeriesNetwork') || isa(net, 'DAGNetwork')
dlnet = dag2dlnetwork(net); % Convert to dlnetwork
mdlInfo = exportNetworkToSimulink(dlnet);
else
error('The trained network must be a SeriesNetwork or DAGNetwork.');
end
Then this simulink model was created.
I'd like to see how this model (my_model_1) works with sample test input data by Constant block like this .
However it doesn't work and I'm not quite sure what type of data I should input here.
I know this model has 7 input signals and predicts 2 output signals.
I'l share my .slx file(my_model.slx).
How would you do if you want put 7 Simulink input signals in this model and put out 2 Simulink output signals?
I was wondering if you could tell me how to solve it...
Best,
The model needs the "dlnet" variable in workspace to run, so I can't try on your model yet. I wonder, if you just use a column vector for the constant, like [1;2;3;4;5;6;7], will the Simulink model accept it and send an output?
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.
I got it. I solved it!
Much appreciated.

Iniciar sesión para comentar.

Más respuestas (1)

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 comentarios

翼
el 26 de Sept. de 2024
Editada: el 26 de Sept. de 2024
Thank you for telling me.
I got it.
I understood I need to use Deep Learning Toolbox for what I want.
By the way,
I wonder if I don't need Statistics and Machine Learning Toolbox to use Deep Learning Toolbox...
I mean, am I right in thinking all I need to do is only use Deep Learning Toolbox?
If you don't mind, in my case, I'd appreciate it if you could tell me how to train my data and make the model with Deep Learning Toolbox!
(Model that predict 2 outputs based on 7 inputs)
Best,
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:
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")
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Productos

Versión

R2024b

Etiquetas

Preguntada:

翼
el 23 de Sept. de 2024

Comentada:

el 23 de Oct. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by