How to import a random forest regression model (made with sklearn (scikit-learn) in python) into Simulink?
조회 수: 15 (최근 30일)
이전 댓글 표시
Hi, I created a random forest regression model in python using sklearn with the following function:
Now, I need to implement this model in Simulink for further use, I tried to save the files with Joblib, ONNX and HDF5 files in python, read these files in MATLAB and then implement it in Simunlink as an LTI-system but with no succes.
used py.pickle.load(py.open('Filename.sav','rb'))
ONNX: https://onnx.ai/sklearn-onnx/
used importONNXNetwork('Filename.onnx')
Any Idea how to import a model created with sklearn in python into Simulink?
Thanks in advance
댓글 수: 0
답변 (1개)
Surya
2023년 4월 20일
편집: Surya
2023년 4월 20일
Hi,
You can make use of MATLAB Python interface. check
You can create a MATLAB function block in Simulink and use python commands directly in the function.
Example MATLAB funtion (For training):
regressor = py.sklearn.ensemble.RandomForestRegressor(n_estimators=100, random_state=0)
regressor.fit(x, y)
py.joblib.dump(regressor, "./random_forest.joblib")
Example MATLAB funtion (For loading the model):
loaded_rf = py.joblib.load("./random_forest.joblib")
For this to work, you need python installed in you system which is compatible with MATLAB. check compatibility
Install required libraries in Python using pip.
Hope it helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 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!