Simple Example of Logistic Regression
In this example, we train an external scikit-learn model to use for making predictions.Creating the Ray Serve Model
Let’s look at an actual model wrapped by a class that complies with the requirements./train
and /predict
endpoints.
The /train
endpoint accepts two parameters to be sent via POST:
df
is a serialized dictionary that can be converted into a pandas dataframe.target
is the name of the target column to be predicted.
status
key and the ok
value.
The /predict
endpoint requires one parameter to be sent via POST:
df
is a serialized dictionary that can be converted into a pandas dataframe.
prediction
key. It stores the
predictions. Additional keys can be returned for confidence and confidence
intervals.
Bringing the Ray Serve Model to MindsDB
Once you start the RayServe-wrapped model, you can create and train it in MindsDB.SELECT
statement to learn more.
You can directly pass input data in the WHERE
clause to get a single
prediction.
JOIN
the model wth a data table to get bulk predictions.
Limit for POST RequestsPlease note that if your model is behind a reverse proxy like nginx, you might
have to increase the maximum limit for POST requests in order to receive the
training data. MindsDB can send as much as you’d like - it has been
stress-tested with over a billion rows.
Example of Keras NLP Model
Here, we consider a natural language processing (NLP) task where we want to train a neural network using Keras to detect if a tweet is related to a natural disaster, such as fires, earthquakes, etc. Please download this dataset to follow the example.Creating the Ray Serve Model
We create a Ray Serve service that wraps around the Kaggle NLP Model that can be trained and used for making predictions.nlp_kaggle_train
to load the
dataset that the original model
uses. The nlp_kaggle_train
table contains the following columns:
Bringing the Ray Serve Model to MindsDB
Now, we can create and train this custom model in MindsDB.trained
, you can fetch
predictions using the standard MindsDB syntax. Follow the guide on the
SELECT
statement to learn more.
1
.
0
.
Wrong Results?If your results do not match this example, try training the model for a longer
amount of epochs.
Get More InsightsCheck out the article on How to bring your own machine learning model to databases by Patricio Cerda Mardini to learn more.