Repository: mindsdb/mindsdb

Issue:
Export model
Hi Adam, I tried replying to your email but it bounced.

1 question, can models be exported to enable prediction on another machine? 
For home automation where people are running their system on a raspberry pi, a workflow I can envision is exporting data to csv (we have a platform for doing that https://data.home-assistant.io/), training e.g. on colab, then exposing the model to the home automation system via a rest API from a docker container.
Thanks


Discussion:
Hi @robmarkcole 

Thank you, I will add it to the todo list, to be able to export models easily, there is a way, by which you copy the mindsdb module files from your python path to your target machine, however, if you want to help us try it out, I will let you know as soon as the option of exporting a model is available.

I would really like this functionality.
Also because I could easily give my model to someone else without giving them the data.
This is especially important when working with private data, such as health information.

At the same time, I also tried replying to your mail but it bounced.
Keep up the great work.
Working on this, thank you for your ideas :)
On Thu, Jan 10, 2019 at 1:48 PM Yannick Bijl <notifications@github.com>
wrote:

> I would really like this functionality.
> Also because I could easily give my model to someone else without giving
> them the data.
> This is especially important when working with private data, such as
> health information.
>
> At the same time, I also tried replying to your mail but it bounced.
> Keep up the great work.
>
> —
> You are receiving this because you commented.
>
>
> Reply to this email directly, view it on GitHub
> <https://github.com/mindsdb/mindsdb/issues/57#issuecomment-453266602>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/AFoBCkvftSK_rpxXrWR8UoJLDHw8rFOFks5vB7UxgaJpZM4Z48zp>
> .
>

This is currently done via the `export` and `load` functions.
However... I'm not yet certain it always works with the way ludwig stores data, so I'll keep this open until I'm 100% sure we store the ludwig data properly in all cases.

Still, feel free to try the `export` and `load` in the master branch, they should *usually* work.

`export` produces a .zip file and `load` takes the name of said zipfile as arguments.

Resolving patch:
diff --git a/mindsdb/libs/controllers/predictor.py b/mindsdb/libs/controllers/predictor.py
--- a/mindsdb/libs/controllers/predictor.py
+++ b/mindsdb/libs/controllers/predictor.py
@@ -62,15 +62,15 @@ def __init__(self, name, root_folder=CONFIG.MINDSDB_STORAGE_PATH, log_level=CONF
             error_message = '''Cannot write into storage path, please either set the config variable mindsdb.config.set('MINDSDB_STORAGE_PATH',<path>) or give write access to {folder}'''
             raise ValueError(error_message.format(folder=CONFIG.MINDSDB_STORAGE_PATH))
 
-    def export(self, model_zip_file='mindsdb_storage'):
+    def export(self, mindsdb_storage_dir='mindsdb_storage'):
         """
         If you want to export this mind to a file
-        :param model_zip_file: this is the full_path where you want to store a mind to, it will be a zip file
+        :param mindsdb_storage_dir: this is the full_path where you want to store a mind to, it will be a zip file
 
         :return: bool (True/False) True if mind was exported successfully
         """
         try:
-            shutil.make_archive(model_zip_file, 'zip', CONFIG.MINDSDB_STORAGE_PATH)
+            shutil.make_archive(mindsdb_storage_dir, 'zip', CONFIG.MINDSDB_STORAGE_PATH)
             return True
         except:
             return False
@@ -288,14 +288,14 @@ def get_model_data(self, model_name):
 
         return amd
 
-    def load(self, model_zip_file='mindsdb_storage.zip'):
+    def load(self, mindsdb_storage_dir='mindsdb_storage.zip'):
         """
         If you want to import a mind from a file
 
-        :param model_zip_file: this is the full_path that contains your mind
+        :param mindsdb_storage_dir: this is the full_path that contains your mind
         :return: bool (True/False) True if mind was importerd successfully
         """
-        shutil.unpack_archive(model_zip_file, extract_dir=CONFIG.MINDSDB_STORAGE_PATH)
+        shutil.unpack_archive(mindsdb_storage_dir, extract_dir=CONFIG.MINDSDB_STORAGE_PATH)
 
     def learn(self, to_predict, from_data = None, test_from_data=None, group_by = None, window_size_samples = None, window_size_seconds = None,
     window_size = None, order_by = [], sample_margin_of_error = CONFIG.DEFAULT_MARGIN_OF_ERROR, ignore_columns = [], rename_strange_columns = False,


Test patch: