Scikit Learn Model Predict — Machine Learning/Python Models
Machine_Learning/Python_Models/Scikit_Learn_Model_Predict · 1 input / 1 output port(s) at insert · exports to Python
Description#
The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.
Scikit-learn Model Predict
Machine Learning / Python Models
Runs a saved scikit-learn estimator on the input, once per sample: y = model.predict(x). The estimator is loaded from its file when the run starts and called in the embedded Python interpreter, the way MATLAB’s Scikit-learn Model Predict block calls it.
Ports
- Input – x, the features. A vector (a column or a row) of n is one observation, handed to predict as a (1, n) array; an m×n matrix is m observations, one per row. It is cast to the Input Data Type first.
- Output – y, what predict returns: one value per observation, so [1,1] for a vector input and [m,1] for m observations. A 2-D result keeps its shape. Class labels arrive as numbers; an estimator that predicts text cannot drive a port.
Parameters
- Model File – the file the estimator was saved to. Empty runs a built-in example estimator, y = 0.5·(the sum of the features) + 0.25, which needs no scikit-learn. A relative path is read from the directory the app was started in.
- Model Load Command – how the file is read:
- pickle.load() – a pickle file.
- joblib.load() – a joblib file; needs joblib.
- skops.io.load() – a skops file, loaded as trusted; needs skops.
- Input Data Type – the numpy type the input is cast to before predict: float32 (the default, as in MATLAB’s block), float64, float16, float, int8, int16, int32, int64, int, uint8, uint16, uint32 or uint64. The cast rounds (float32) or truncates (the integer types), and the estimator sees the cast values.
- Preprocessing File – optional: a Python file defining
preprocess(model, inputs), which receives the list of input arrays and returns the list predict gets. - Postprocessing File – optional: a Python file defining
postprocess(model, outputs), which receives predict’s list and returns the list the output takes. - Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.
Code export
Python only – the generated module loads the estimator from the same file and calls it exactly as the simulation does. The other nine targets (MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text) are not supported: none can carry a Python interpreter, so an export to any of them fails loudly for this block.
Simulink bridge
Both directions, to statsPycoex/Scikit-learn Model Predict. Model File
↔ ModelFile, Model Load Command ↔ ModelLoadCommand (its
three options 1:1), Preprocessing File ↔ PreprocessingFilePath,
Postprocessing File ↔ PostprocessingFilePath, and Input Data Type
crosses as the type column of InputTable. Input and output permutations have no
setting here and are reported, not crossed. A block on the built-in example has no file to
name and is reported on export. Sampling Time (s) → SampleTime, as on every block.
Notes
- Discrete by nature: the estimator is called once per sample, never integrated.
- Before the first sample predict runs once on inputs of all ones, as in MATLAB’s block; the output size is taken from it and must not change during the run.
- Needs the Python runtime, and scikit-learn wherever a real model file is named; a model that fails to load or to predict is reported once, with the block’s path, and stops the run.
Code facts#
| Fact | Value |
|---|---|
| registered type | Machine_Learning/Python_Models/Scikit_Learn_Model_Predict |
| family | Machine_Learning/Python_Models |
| solver environment class | ICoreBlock_0_Machine_Learning_1_Python_Models_2_Scikit_Learn_Model_Predict |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Machine_Learning/Python_Models/Scikit_Learn_Model_Predict/ICoreBlock_0_Machine_Learning_1_Python_Models_2_Scikit_Learn_Model_Predict.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Machine_Learning/Python_Models/Scikit_Learn_Model_Predict/ICoreBlock_0_Machine_Learning_1_Python_Models_2_Scikit_Learn_Model_Predict.h |
| default size on canvas | 130 × 80 px |
| ports at insert | 1 in, 1 out |
| code generators implemented | Python |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreDouble | — |
| 2 | out | ICoreDouble | — |
Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.
Configuration variables#
| Config variable | Default | Simulink parameter |
|---|---|---|
Model File | — | ModelFile |
Model Load Command | pickle.load()%~%joblib.load()%~%skops.io.load()~~pickle.l… | ModelLoadCommand |
Input Data Type | comboOptions() | not crossed |
Preprocessing File | — | PreprocessingFilePath |
Postprocessing File | — | PostprocessingFilePath |
Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.
Simulink bridge#
| support | Support::Both |
| Simulink path | statsPycoex/Scikit-learn Model Predict |
| port-count rule | PortsParam::PycoexSklearnTable |
SampleTime parameter | yes |
| deliberately not crossed | Input Data Type |
| ICore config | Simulink parameter | Value translation |
|---|---|---|
Model File | ModelFile | passes through |
Model Load Command | ModelLoadCommand | passes through |
Preprocessing File | PreprocessingFilePath | passes through |
Postprocessing File | PostprocessingFilePath | passes through |
Caveat (shown to the user): "Input Data Type crosses as InputTable's type column
Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h
Description vs code#
The lists agree. check_block_descriptions.py finds no disagreement between the description's Ports, Parameters, Code export and Simulink bridge lists and the code's.
The verdict above is
tools/docs/check_block_descriptions.py(P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.
File banner (developer view)#
The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).
Scikit-learn Model Predict -- a saved scikit-learn estimator's predict, sample by sample statsPycoex/Scikit-learn Model Predict loads an estimator from a file and calls its predict once per sample, through MATLAB's Python co-execution. This block does the same in the embedded interpreter, under the contract measured on R2026a and written up in ICorePythonModelSupport: the input cast to its numpy type (float32 unless set), a vector handed over as ONE observation -- a (1, n) row -- and an m x n matrix as m observations; one predict on inputs of all ones before the run; the prediction back as a matrix.
With no Model File the block runs a built-in example estimator (y = 0.5 * the sum of the features + 0.25), so its factory configuration runs where scikit-learn is not installed.
DISCRETE-ONLY: called once per sample, never integrated. Python-only export.
Sample results#
| t | in ICoreDouble-Out-0 | out ICoreDouble-Out-0 |
|---|---|---|
| 0 | -2 | -0.75 |
| 0.4 | 0.5 | 0.5 |
| 0.8 | -2 | -0.75 |
| 1.2 | 0.5 | 0.5 |
| 1.6 | -2 | -0.75 |
| 2 | 0.5 | 0.5 |
| 2.4 | -2 | -0.75 |
| 2.8 | 0.5 | 0.5 |
| 3.2 | -2 | -0.75 |
| 3.6 | 0.5 | 0.5 |
| 4 | -2 | -0.75 |
| 4.4 | 0.5 | 0.5 |
| 4.8 | -2 | -0.75 |
| 5.2 | 0.5 | 0.5 |
Every 4th of 60 samples, from the table stimulus.
The same rig also ran:
| Stimulus | What it is | Output range |
|---|---|---|
impulse | Impulse: one sample of 1 at k = 5, 0 elsewhere (Repeating Sequence Stair) | 0.25 … 0.75 |
ramp | Ramp: slope 1 from t = 0 | 0.25 … 3.2 |
sine | Sine Wave: amplitude 1, 2 rad/s, no phase, no bias | -0.25 … 0.7498 |
step | Step: 0 -> 1 at t = 1 s | 0.25 … 0.75 |
Plotted: table — Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample
Category static · sample time 0.1 · 60 steps · commit c3e68843be2458022bf387235205d5741823eb64 · produced by docsSample --out <folder> --blocks Scikit_Learn_Model_Predict Custom_Python_Model_Predict --steps 60 · data docs/generated/samples/Machine_Learning__Python_Models__Scikit_Learn_Model_Predict.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).