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!

 Akzeptierte Antwort

Hans Scharler
Hans Scharler am 10 Apr. 2020

1 Stimme

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 Kommentare

Vinod
Vinod am 10 Apr. 2020
Bearbeitet: Vinod am 10 Apr. 2020
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.
Vinod
Vinod am 10 Apr. 2020
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 am 21 Aug. 2020
Bearbeitet: Abhishek Pokhrel am 21 Aug. 2020
@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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

MAHESH D
MAHESH D am 19 Mär. 2024
Bearbeitet: MAHESH D am 19 Mär. 2024

0 Stimmen

@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

Communitys

Weitere Antworten in  ThingSpeak Community

Kategorien

Mehr zu Visualize Data finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by