How to import a pre trained linear regression model from python to matlab?
이전 댓글 표시
If I trained a model using python. Is there any way to import or use that model in matlab? Finally I want to genarate a c code after adding something to that in matlab.
댓글 수: 3
Image Analyst
2020년 5월 5일
What format is your model in? To generate code, you'll need the MATLAB Code Toolbox.
chaitanya kalipatnapu
2020년 5월 5일
chaitanya kalipatnapu
2020년 5월 5일
답변 (1개)
David Fink
2020년 5월 5일
1 개 추천
To import from Python to MATLAB, save the model in a format MATLAB can import:
or a simpler format, like text or csv.
To generate C code from the imported model, use MATLAB Coder or GPU Coder:
댓글 수: 5
chaitanya kalipatnapu
2020년 5월 6일
David Fink
2020년 5월 6일
Ah, my mistake assuming you were using a neural network.
For simple regression models, the coefficients are usually just one vector, right?
For logistic regression, a few lines of MATLAB can use the coefficient vector and input to produce output, similar to the mymodelfun function in this example:
For getting the data from python into MATLAB, it sounds like pickle uses its own binary format. With your command, it named the file with a ".mat" extension, but doesn't follow the MathWorks ".mat" format.
I'd recommend saving the vector of coefficients as a text or csv file, and importing to MATLAB via readmatrix or importdata.
shayne sudhakar
2021년 5월 5일
Hi David, I have a similar question. I have a model trained in python and have the model saved in csv. How could I import the model in matlab and then convert it into a simulink block ?
Basically what I need to do is the same as what the gensim function does to a trained matlab network.
Could you please assist me with this.
David Willingham
2021년 5월 5일
Hi Shayne,
Here is an example that shows how to call GoogLeNet into Simulink using the MATLAB function block:
Also, there are the following blocks that support calling popular model types directly:
shayne sudhakar
2021년 5월 14일
편집: shayne sudhakar
2021년 5월 14일
Hi David,
Thanks for your advise.
I tried this, but I was able to directly get a .h5 file of model weights from keras.
So importkeraslayers(model file) worked well.
But unfortunately the gensim(net) function does not operate on the 'net' file generated from the importkeraslayers function. It shows an error of incorrect argument datatype or missing argument in call to function 'gensim'
Can you provide me with some insight on this. Thanks a ton.
Shayne
카테고리
도움말 센터 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!