LightFM
The LightFM handler functions as an interface for the LightFM Python recommendation library. The current implementation supports collaborative filtering for user-item and item-item recommendations. It allows users to make use of the powerful LightFM recommendation framework library for performing recommendation on interaction data sets.
Prerequisites
Before proceeding, ensure the following prerequisites are met:
- Install MindsDB locally via Docker or Docker Desktop.
- To use LightFM within MindsDB, install the required dependencies following this instruction.
Please note that, if you are using Docker to run MindsDB, before installing the dependencies for this integration as per the instructions given above, it is currently necessary to install a couple of Linux development packages in the container. To do this, run the following commands:
Start an interactive shell in the container:
If you haven’t specified a name when spinning up the MindsDB container with docker run
, you can find it by running docker ps
.
Install the required Linux development packages:
As the current implementation stands, the input data should be a table containing user-item interaction data:
Please note that at the moment this integration does not support the FINETUNE
feature.
Example
Before creating a LightFM model, we need to create an ML engine.
You can verify it by running SHOW ML_ENGINES
.
Now let’s create a LightFM model specifying the necessary input parameters.
The required parameters include the following:
- The
item_id
parameter that stores items to be recommended; here, these are movies. - The
user_id
parameter that stores users to whom items are recommended. - The
threshold
parameter is used when score of interaction is provided in the input data. It defines the threshold for the recommendation. - The
n_recommendations
parameter stores the number of recommendations to be returned.
Optionally, you can provide the evaluation
parameter if you want to store the evaluation metrics. It is set to false
by default.
Here is how to connect the mysql_demo_db
used for training the model:
Let’s query for the following recommendations:
-
Get recommendations for all item_item pairs:
-
Get item-item recommendations for a specific item_id:
-
Get recommendations for all user-item pairs:
-
Get user-item recommendations for a specific user_id:
-
Get user-item recommendations for multiple user_ids:
Was this page helpful?