forum.alglib.net http://forum.alglib.net/ |
|
Question about random forest model http://forum.alglib.net/viewtopic.php?f=2&t=4469 |
Page 1 of 1 |
Author: | johnnix [ Sun Jul 03, 2022 7:07 am ] |
Post subject: | Question about random forest model |
Hello, I am evaluating ALGLIB to be used inside one of my commercial software programs in order to offer my users an easy way to use random forest models for their data. It looks ok so far but I was not able to find a way to "save" the trained model so that it can be loaded and used again. Is this possible? Thank you all for your time! Regards John |
Author: | Sergey.Bochkanov [ Sun Jul 03, 2022 8:48 am ] |
Post subject: | Re: Question about random forest model |
Hi! It can be performed with dfserialize()/dfunserialize() pair of functions. Random forest can be serialized to string or stream. The data are written using compressed text format, i.e. you can write it to text or XML file, change EOL between Windows and Unix style, and it will work. It is also possible to move models between C++ and C# versions of the library (e.g. train in C++ and use in C#). Sergey |
Author: | johnnix [ Sun Jul 03, 2022 10:03 am ] |
Post subject: | Re: Question about random forest model |
That is great! I will proceed with purchasing the commercial version :) |
Author: | shaos [ Tue Aug 15, 2023 3:31 pm ] |
Post subject: | Re: Question about random forest model |
hiļ¼can you provide a code demo to use the dfserialize /dfunserialize function? does it correct if i ues it as: Code: Qstring outModelDir_path = "D:/out" decisionforest model; string outModelFilePath = outModelDir_path.toStdString() + "/trainedModel.txt"; string outModel; dfserialize(model, outModel); ofstream outModelFile(outModelFilePath.c_str(), ios::out); outModelFile << outModel; i am not sure whether is the right way to use it. it seems the serialized data look like:
G-v10000000 G-v10000000 0000000XZ24 00000000000 xHXh75kUqz3 00000009I24 00000000004 IZFKb9iDO_3 0000000qD24 00000000S04 U0WFcfm5-y3 0000000w824 00000000m_3 ScN__emr404 0000000mN14 00000000004 gelTaGVEf-3 0000000WJ14 00000000G04 aoxCpC6RG-3 0000000W914 00000000K04 9aSgjX2Lwz3 00000000z04 00000000m_3 looking for your help! |
Author: | Sergey.Bochkanov [ Wed Aug 16, 2023 10:44 am ] |
Post subject: | Re: Question about random forest model |
Hi! Yes, it is a right way to do. The model is serialized in a portable text format which can tolerate all types of issues arising when moving text between machines and operating systems. In particular, it does not contain non-ASCII symbols, can easily tolerate conversion between Windows and Unix newlines and so on. Sergei |
Author: | shaos [ Wed Aug 16, 2023 1:33 pm ] |
Post subject: | Re: Question about random forest model |
Thats cool! Thanks for your thoughtful work to make it easy to use! Best regards! shaos |
Author: | shaos [ Sun Aug 20, 2023 5:01 am ] |
Post subject: | Re: Question about random forest model |
hi! By following your suggestion, i successfully serialized the model to txt. I didnot find any demo code in guidebook, is it correct to use dfunserialize function following the code below? i use C++ to finish this work Code: string loadModel(string serializedModelFileStringFormatPath) { ifstream serializedModelFile(serializedModelFileStringFormatPath); if (!serializedModelFile.is_open()) { cout << cannot open serialized data" << endl; return "cannot open serialized data"; } ostringstream tmp; tmp << serializedModelFile.rdbuf(); string data = tmp.str(); serializedModelFile.close(); return data; } int main( string inModelFilePath = "c:/test/inmodel.txt"; string modelContent = loadModel(inModelFilePath); decisionforest model; dfunserialize(modelContent, model); double esti = dfprocess0(model, rowItem); { I would appreciate a lot!! shaos |
Author: | Sergey.Bochkanov [ Thu Aug 24, 2023 12:22 pm ] |
Post subject: | Re: Question about random forest model |
Yes, you are right, it must work |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |