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!

 Respuesta aceptada

Hans Scharler
Hans Scharler el 10 de Abr. de 2020
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 comentarios

Vinod
Vinod el 10 de Abr. de 2020
Editada: Vinod el 10 de Abr. de 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 el 10 de Abr. de 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 el 21 de Ag. de 2020
Editada: Abhishek Pokhrel el 21 de Ag. de 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!

Iniciar sesión para comentar.

Más respuestas (1)

MAHESH D
MAHESH D el 19 de Mzo. de 2024
Editada: MAHESH D el 19 de Mzo. de 2024
@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

Comunidades de usuarios

Más respuestas en  ThingSpeak Community

Categorías

Más información sobre Visualize Data en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 10 de Abr. de 2020

Editada:

el 19 de Mzo. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by