Learning

Before making any intelligent predictions, each model type requires labels to learn from. To learn, send the labeled data to a /learn or /reward endpoint. The act of a model learning from data is referred to as training or updating. mlrequest uses online learning models, therefore to update a model with new labeled data you do not need to send the previous labeled data you used to originally train the model. The model will update incrementally from its current state.

Continuing the rainy weather predicting model from earlier sections, a request to a learn endpoint might look like the examples below.

Python Client
Python
Javascript
Java
Go
Ruby
C#
from mlrequest import Classifier
classifier = Classifier('your-api-key')
features = {
'skies': 'cloudy',
'temperature': 45,
'pressure': 29.87
}
training_data = {'features': features, 'label': 2}
r = classifier.learn(training_data=training_data, model_name='rain-or-shine', class_count=2)
import requests
features = {
'skies': 'cloudy',
'temperature': 45,
'pressure': 29.87
}
payload = {
'model_name': 'rain-or-shine',
'class_count': 2,
'features': features,
'label': 2
}
r = requests.post('https://api.mlrequest.com/v1/classifier/learn', json=payload, headers={'MLREQ-API-KEY':'your-api-key'})
Coming soon...
Coming soon...
Coming soon...
Coming soon...
Coming soon...

Model updates happen asynchronously and occur ~30 seconds after submitting data.

In the classification example above, 'label': 2 might correspond to rainy weather. Classification labels are always given in integer format and are mapped to the label name you care about. In this example, 'label': 1 corresponds to sunny weather, and 'label': 2 corresponds to rainy weather. See the model types guide to learn more about the input and output of each model, and what types of use cases are well suited for each of them.

If your data permits, always update the model with labels that are in a randomized order. Sending data in batches of one label, then another can cause the model to get "stuck" and produce undesired results.

When to Call a Learn Endpoint

Some models may require being updated very frequently, and some may be trained all at once and then never touched again. It is up to you and what is best for your application to decide how often you want your model to learn.

Below is a table that describes model training based on frequency with examples.

Model Training Frequency

Example

Once a month or longer

A model that predicts how successful a customer service chat session will be, trained on text from previous chat sessions.

Once a day

A model that predicts the type of mobile app user (avid, casual, etc.) on logging in to show relevant in-app marketing.

A model that predicts which daily marketing email to send, based on previous emails and their clickthrough rates.

Whenever a label is available

A model that recommends new products to users based on their interactions and their previous buying profile.

A model that offers discounts to visitors of an app or ecommerce store, if they are likely to leave before purchasing.

It comes down to how often trends are changing in your labeled data. Sometimes trends change infrequently (e.g., text analytics, weather patterns), but other times they can change very frequently (e.g., customer interests).