lightfm | Python implementation of LightFM , a hybrid recommendation | Recommender System library

 by   lyst Python Version: 1.17 License: Apache-2.0

kandi X-RAY | lightfm Summary

kandi X-RAY | lightfm Summary

lightfm is a Python library typically used in Artificial Intelligence, Recommender System applications. lightfm has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can install using 'pip install lightfm' or download it from GitHub, PyPI.

LightFM is a Python implementation of a number of popular recommendation algorithms for both implicit and explicit feedback, including efficient implementation of BPR and WARP ranking losses. It's easy to use, fast (via multithreaded model estimation), and produces high quality results. It also makes it possible to incorporate both item and user metadata into the traditional matrix factorization algorithms. It represents each user and item as the sum of the latent representations of their features, thus allowing recommendations to generalise to new items (via item features) and to new users (via user features). For more details, see the Documentation. Need help? Contact me via email, Twitter, or Gitter.

            kandi-support Support

              lightfm has a highly active ecosystem.
              It has 4348 star(s) with 668 fork(s). There are 93 watchers for this library.
              It had no major release in the last 12 months.
              There are 130 open issues and 354 have been closed. On average issues are closed in 50 days. There are 12 open pull requests and 0 closed requests.
              It has a negative sentiment in the developer community.
              The latest version of lightfm is 1.17

            kandi-Quality Quality

              lightfm has 0 bugs and 0 code smells.

            kandi-Security Security

              lightfm has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              lightfm code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              lightfm is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              lightfm releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              lightfm saves you 1057 person hours of effort in developing the same functionality from scratch.
              It has 2488 lines of code, 156 functions and 22 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed lightfm and discovered the below as its top functions. This is intended to give you an instant insight into lightfm implemented functionality, and help decide if they suit your requirements.
            • Downloadovielens
            • Convert the matrix to a coo_matrix object
            • Calculate the dimensions of the dataset
            • Build interaction matrix
            • Return metadata for a movie item
            • Return the path to movielens zip files
            • Download the movielens dataset
            • Get the raw metadata
            • Calculate the recall of a given model
            • Constructs a matrix representation of the feature matrix
            • Checks that the test interaction between test interactions
            • Predict the rank of the graph
            • Gets the covariance matrix fromovielens data
            • Get the raw movielens data
            • Run the lightfm
            • Generate code for pyx
            • Compute reciprocal rank
            • Define the list of supported extensions
            Get all kandi verified functions for this library.

            lightfm Key Features

            No Key Features are available at this moment for lightfm.

            lightfm Examples and Code Snippets

            LightFM Dataset helper,Example,Creating the helper instance
            Pythondot img1Lines of Code : 34dot img1License : Permissive (MIT)
            copy iconCopy
            dataset_helper_instance = DatasetHelper(
            Pre-train LightFM,Method
            Pythondot img2Lines of Code : 28dot img2no licencesLicense : No License
            copy iconCopy
            def __init__(self, no_components=10, k=5, n=10,
                             learning_rate=0.05, rho=0.95, epsilon=1e-6,
                             item_alpha=0.0, user_alpha=0.0, max_sampled=  
            copy iconCopy
            # using pandas to load csv files
            import pandas as pd
            def read_csv(filename):
                return pd.read_csv(filename, sep=";", error_bad_lines=False, encoding="latin-1", low_memory=False)
            books = read_csv("Data/BX-Books.csv")
            users = read_csv("Data/BX-User  

            Community Discussions


            LightFM how to make predictions for new users (cold start) - user id 8 not in user id mappings
            Asked 2022-Mar-26 at 12:28

            I am building a recommendation system in order to recommend training to employees based on user features and item features which LightFM according to the documentation its a great algorithm.

            my user dataframe:



            Answered 2022-Mar-26 at 12:28

            I cannot test it, but I think the problem is when you write:



            DataError: No numeric types to aggregate pandas pivot
            Asked 2022-Mar-21 at 15:56

            I have a pandas dataframe like this:



            Answered 2022-Mar-21 at 15:56

            The Pandas Documentation states:

            While pivot() provides general purpose pivoting with various data types (strings, numerics, etc.), pandas also provides pivot_table() for pivoting with aggregation of numeric data

            Make sure the column is numeric. Without seeing how you create trainingtaken I can't provide more specific guidance. However the following may help:

            1. Make sure you handle "empty" values in that column. The Pandas guide is a very good place to start. Pandas points out that "a column of integers with even one missing values is cast to floating-point dtype".
            2. If working with a dataframe, the column can be cast to a specific type via your_df.your_col.astype(int) or for your example, pd.trainingtaken.astype(int)



            predict new user using lightfm
            Asked 2021-Sep-21 at 10:15

            I want to give a recommendation to a new user using lightfm.

            Hi, I've got model, interactions, item_features. The new user is not in interactions and the only information of the new user is their ratings.(list of book_id and rating pairs)

            I tried to use predict() or predict_rank(), but I failed to figure out how. Could you please give me some advice?

            Below is my screenshot which raised ValueError..



            Answered 2021-Sep-21 at 10:15

            I was having the same problem, What I did was

            1. Created a user_features matrix (based on their preferences) using Dataset class



            Scipy coo_matrix.max() alters data attribute
            Asked 2020-Dec-30 at 23:18

            I am building a recommendation system using an open source library, LightFM. This library requires certain pieces of data to be in a sparse matrix format, specifically the scipy coo_matrix. It is here that I am encountering strange behavior. It seems like a bug, but it's more likely that I am doing something wrong.

            Basically, I let LightFM.Dataset build me a sparse matrix, like so:



            Answered 2020-Dec-30 at 23:18

            A 'raw' coo_matrix can have duplicate elements (repeats of the same row and col values), but when converted to csr format for calculations those duplicates are summed. It must be doing the same, but in-place, in order to find that max.



            Lightfm Incorrect number of features in user_features
            Asked 2020-Dec-15 at 16:03

            I am building recommender system - hybrid in Lightfm. My data has 39326 unique users and 2569 unique game titles(items). My train interaction sparce matrix has shape: <39326x2569 sparse matrix of type '' with 758931 stored elements in Compressed Sparse Row format> My test interaction sparce matrix has shape:<39323x2569 sparse matrix of type '' with 194622 stored elements in Compressed Sparse Row format>

            I train model: model1 = LightFM(learning_rate=0.01, loss='warp'),
            epochs=20) which creates object: But when I try to check accuracy by: train_precision = precision_at_k(model1, train_interactions, k=10).mean() test_precision = precision_at_k(model1, test_interactions, k=10).mean()

            I get error message: Incorrect number of features in user_features WHY??? Clearly the shapes are compatible? What am I missing?



            Answered 2020-Dec-15 at 16:03

            Your test sparse matrix is of dimension 39323x2569 while your train sparse matrix is of dimension 39326x2569. You are missing 3 users in your test set.

            I suggest you use the lightfm built-in train/test split function to avoid errors :

            If you want to split your data in your own way, you can also transform your user_id and item_id to consecutive integers starting from 0. And then use this :



            Import rasterio failed. Reason: image not found
            Asked 2020-Sep-22 at 05:37

            I'm going to use rasterio in python. I downloaded rasterio via



            Answered 2020-Sep-22 at 05:37

            I've got some experience with rasterio, but I am not nearly a master with it. If I remember correctly, rasterio requires you to have installed the program GDAL(both binaries and python utilities), and some other dependencies listed on the PyPi page. I don't use conda at the moment, I like to use the regular python 3.8 installer with pip. Given what I'm seeing with your installation, I would uninstall rasterio and follow a different installation procedure.

            I follow the instructions listed here:
            This page also has separate instructions for those using Anaconda.

            The GDAL installation is by far the most annoying but once it's done, the hard part is over. The python utilities for both rasterio and gdal can be found here:
            The second link is also provided on the PyPi page but I like to keep it bookmarked because there's a lot of good resources there!


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install lightfm

            Fitting an implicit feedback model on the MovieLens 100k dataset is very easy:.


            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • PyPI

            pip install lightfm

          • CLONE
          • HTTPS


          • CLI

            gh repo clone lyst/lightfm

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link