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:
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.
The BYOM feature can be configured with the following environment variables:
MINDSDB_BYOM_ENABLEDThis environment variable defines whether the BYOM feature is enabled (MINDSDB_BYOM_ENABLED=true) or disabled (MINDSDB_BYOM_ENABLED=false). Note that by default, it is disabled.Alternatively, you can enable it in the MindsDB configuration file:
{ "byom": { "enabled": true }}
MINDSDB_BYOM_DEFAULT_TYPEThis environment variable defines the modes of operation of the BYOM feature.
MINDSDB_BYOM_DEFAULT_TYPE=venv
When using the venv mode, MindsDB creates a virtual environment and installs in it the packages listed in the requirements.txt file. This virtual environment is dedicated for the custom model. Note that when running MindsDB locally, it is the default mode.
MINDSDB_BYOM_DEFAULT_TYPE=inhouse
When using the inhouse mode, there is no dedicated virtual environment for the custom model. It uses the environment of MindsDB, therefore, the requirements.txt file is not used with this mode.
MINDSDB_BYOM_INHOUSE_ENABLEDThis environment variable defines whether the inhouse mode is enabled (MINDSDB_BYOM_INHOUSE_ENABLED=true) or disabled (MINDSDB_BYOM_INHOUSE_ENABLED=false). Note that when running MindsDB locally, it is enabled by default.
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_modelFROM my_integration (SELECT * FROM my_table)PREDICT targetUSING ENGINE = 'custom_model_engine';
Let’s query for predictions by joining the custom model with the data table. Please note that when querying for predictions, do not include the target column in the input data selection.
SELECT input.feature_column, model.target AS predicted_targetFROM my_integration.my_table AS inputJOIN custom_model AS model;