The Bring Your Own Model (BYOM) feature lets you upload your own models in the form of Python code and use them within MindsDB.

How It Works

You can upload your custom model via the MindsDB editor by clicking Add and Upload custom model, like this:

Here is the form that needs to be filled out in order to bring your model to MindsDB:

Let’s briefly go over the files that need to be uploaded:

  • The Python file stores an implementation of your model. It should contain the class with the implementation for the train and predict methods. Here is the sample format:

    class CustomPredictor():
    
        def train(self, df, target_col, args=None):
                <implementation goes here>
                return ''
    
        def predict(self, df):
                <implementation goes here>
                return df
    
  • The optional requirements file, or requirements.txt, stores all dependencies along with their versions. Here is the sample format:

    dependency_package_1 == version
    dependency_package_2 >= version
    dependency_package_3 >= version, < version
    ...
    

Once you upload the above files, please provide an engine name.

Please note that your custom model is uploaded to MindsDB as an engine. Then you can use this engine to create a model.

Let’s look at an example.

Example

We upload the custom model, as below:

Here we upload the model.py file that stores an implementation of the model and the requirements.txt file that stores all the dependencies.

Once the model is uploaded, it becomes an ML engine within MindsDB. Now we use this custom_model_engine to create a model as follows:

CREATE MODEL custom_model
FROM my_integration
    (SELECT * FROM my_table)
PREDICT target
USING
    ENGINE = 'custom_model_engine';

Let’s query for predictions by joining the custom model with the data table.

SELECT input.feature_column, model_target_column
FROM my_integration.my_table as input
JOIN custom_model as model;

Check out the BYOM handler folder to see the implementation details.