Upload trained machine learning model to Thingspeak

Hello,
I trained a machine learning model on MatLab Desktop and the App Classification Learner. Now I want to upload the trained model to the ThingSpeak Cloud, so that I can make predictions with new data in the cloud. How can I do this ?
Thank you in advance!

 채택된 답변

Hans Scharler
Hans Scharler 2020년 4월 10일

1 개 추천

There is a "Developing an IoT Analytics System with MATLAB, Machine Learning, and ThingSpeak" paper linked from the ThingSpeak website that may help you.
In this example, Robert takes the model and generates MATLAB code and includes it as a function.

댓글 수: 10

Vinod
Vinod 2020년 4월 10일
편집: Vinod 2020년 4월 10일
The article demonstrates the preferred approach to train the model on a desktop and embed the trained model parameters in the MATLAB code that is operationalized on ThingSpeak.
Another, less preferred, approach is to upload the trained model to DropBox and have the code operationalized on ThingSpeak pull the model down parameters from DropBox on demand and apply it to the ingested data.
Okay, thanks.
But is there a possibility to upload the trained model like it is exported from the Classification Learner App? So that I can only use the expression in the cloud:
yfit = trainedModel.predictFcn(testdata)
This is how the Classification Learner App suggest the prediction after the export of the model.
When I export the model it is a 1x1 struct with the model parameters.
Depending on how complex it is to recreate the struct you can do that in your script, or, you can export the MAT file to DropBox and pull it in at runtime using the functions I linked above.
Thank you. I am trying the version with the Dropbox. In the code to download the .mat file is a downloadpath. Do you know which download path I have to use so that the ThingSpeak know the variables? Right now the download is successful, but the variables did not get recognized.
Thank you in advance.
Abhishek Pokhrel
Abhishek Pokhrel 2020년 8월 21일
편집: Abhishek Pokhrel 2020년 8월 21일
@Marcel , did you managed to find a solution? I am looking for the same solution as yours. I have trained a classification model and i want to export that model to ThingSpeak so that it can predict based on the real time data.
@Vinod, I would like to know if there's some tutorial related to this.
Hey, yes I managed to find a solution. I used the solution with DropBox. I uploaded the trained model (the .mat file) to DropBox. After that I wrote MatLAB Code that ran in ThingSpeak. This code downloads the model at runtime using pull the model down parameters from DropBox from @Vinod. Next you can use the trained model in your code to make a prediction with your real time data in ThingSpeak. I am getting the new data from a ThingSpeak field. For this I used the function
thingSpeakRead
Then you can apply the read data to your model.
Regarding to the problem with the downloadpath I wrote before. You can write :
downloadPath = pwd;
@Marcel Zehner I try to use function https://www.mathworks.com/matlabcentral/fileexchange/67833-download-files-from-your-dropbox-api-folder-using-matlab but I got some errors. What variable to be specified in the function? for example, dropboxAccessToken,fileNames. I don't know how to use it.
@Vinod In pull the model down parameters from DropBox what the fileNames variable look like? Is a path or just the name of file (i.e. net.mat) ? if it file' path ,what code that I supposed to write?
I write:
fileNames = ["Apps/<IoT with ML in everyday life>/fddfd/net206010.mat"];
but it doesn't work. Can you help me ?
Sorry if my english is hard to understand.
@Sirapadsorn Chaisaen: Just use the filename, you do not need the full path.
fileNames = 'net206010.mat';
@Vinod Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

MAHESH D
MAHESH D 2024년 3월 19일
편집: MAHESH D 2024년 3월 19일

0 개 추천

@Marcel Zehner,@Vinod,@Sirapadsorn Chaisaen can you please share any tutorial of of how you've done this if possible? I am looking for the same solution as yours. I have trained a classification model and i want to export that model (.mat) to ThingSpeak so that it can predict based on the real time data.
Thank you in advance

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

도움말 센터File Exchange에서 Visualize Data에 대해 자세히 알아보기

제품

질문:

2020년 4월 10일

편집:

2024년 3월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by