How do I change the number of inputs and outputs in Scikit-learn model predict block?

2 次查看(过去 30 天)
I've created a scikit-learn model (.pkl file) that has 9 inputs and 4 outputs.
I want to import this model to Scikit-learn model predict block like the attached image,
but it seems like we can not change the number of inputs and outputs in this block....
Is it possible to change it?
How do I solve it?

采纳的回答

Aravind
Aravind 2025-3-5
编辑:Aravind 2025-3-5
Hello @翼,
You cannot modify the number of input and output ports for the "Scikit-learn Model Predict" block. This block is designed to take an observation as input and provide an output. The observation can include multiple features, which correspond to your multiple inputs.
To pass these multiple inputs or observations to your scikit-learn model, you need to send them as a multi-dimensional matrix. By default, rows represent observations, and columns represent the variables or features. However, you can adjust this using the "Permutation To Python" option in the "Input" section of the block parameters. More information on sending multiple inputs to the "Scikit-learn Model Predict" block is available here: https://www.mathworks.com/help/stats/scikitlearnmodelpredict.html#mw_7cdff098-73a0-436a-8583-f31c73bf98ea.
Similarly, the output from the block will also be a matrix, with rows as observations and columns as corresponding outputs. Further details can be found at: https://www.mathworks.com/help/stats/scikitlearnmodelpredict.html#mw_de2d1dfb-17a9-497b-a1f2-0352fd841fde.
To handle 9 inputs and obtain 4 outputs in your Simulink model, you can use “Mux” and “Demux” blocks. “Mux” blocks combine input signals of the same data type and complexity into a single vector, while “Demux” blocks separate and output the elements of a single vector. Use the “Mux” block to combine the 9 features of the input observation and input it to the "Scikit-learn Model Predict" block. Similarly, use a “Demux” block to extract the 4 output features from the observation.
More information about the Mux block is available at https://www.mathworks.com/help/simulink/slref/mux.html, and about the Demux block at https://www.mathworks.com/help/simulink/slref/demux.html.
I hope this clarifies your query.
  2 个评论
翼
2025-3-5
Thank you.
For instance,
What do I set "Permutation To Python" option in the "Input" section of the block parameters in my case?
I took a look at the doccumentation but I'm not sure how to use this option....
I wonder if it is better to use "Mux", "Demux" block instead of using the "Permutation To Python" option....
If you don't mind, I'd be happy if you could tell me about it.
Aravind
Aravind 2025-3-5
Hi @翼,
For your model, the "Mux" and "Demux" blocks should suffice. The "Permutation To Python" option is used when you want to change the dimensions being passed as an input to the block.
The "Permutation To Python" option, internally calls the "permute" function with the arguments given to the option. You can find more details about the "permute" function at https://www.mathworks.com/help/matlab/ref/double.permute.html. As an example, if you wish to switch the rows and columns of the input matrix (that is take a transpose), then you can specify the "Permutation To Python" option to be [2 1].
I hope this clears things up.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Model Statistics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by