Export trained classification model from Classification Learner to use in python

31 ビュー (過去 30 日間)
KEE OOI TING
KEE OOI TING 2023 年 7 月 13 日
コメント済み: CHIKUMBUTSO 2024 年 6 月 24 日
I trained a model from MATLAB using classification learner app, and I would like to use it with python. Is that possible?

回答 (3 件)

Angelo Yeo
Angelo Yeo 2023 年 7 月 13 日
You can save the model parameters via MAT file. In Python's end, you can use scipy.io.loadmat method to import mat file from SciPy. Below is a sample script in Python.
import scipy.io
mat = scipy.io.loadmat('file.mat')

Anuj
Anuj 2023 年 7 月 13 日
Hi KEE,
Yes, You can export you model from MATLAB in the *.mat format using the save() function, specifing the file name and variable of your model then in the python environment you need to import scipy.io moudle to load the *.mat model there.

Ronit
Ronit 2023 年 7 月 13 日
Hi,
Yes, it is possible to use a model trained in MATLAB with Python. You can export from MATLAB using .mat file format. To export your trained model from MATLAB, you can use the 'saveLearnerForCoder' function. Assuming, the trained model is stored in the variable 'trainedModel'.
saveLearnerForCoder('trainedModel', 'myModel.mat');
This will save your trained model as a .mat file, which can then be loaded and used in Python.
To use the exported model in Python, you can utilize the 'scipy.io' module to load the .mat file and access the model.
import scipy.io
mat = scipy.io.loadmat('myModel.mat')
trainedModel = mat['trainedModel']
Now, you can use the 'trainedModel' in Python.
Hope it helps!!
  1 件のコメント
Mariana Melo
Mariana Melo 2023 年 11 月 22 日
編集済み: Mariana Melo 2023 年 11 月 22 日
Do you have a sample of how to use the exported model in Python? The exported one with this function seems different than the usual way to create a model in Python.
Thank you very much!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by