Skip to content

onurboyar/recompy

 
 

Repository files navigation

Recompy

Recompy is a library for recommender systems. It provides an easy framework to train different models, calculate similarities and recommend items for both existing and new users.

Recompy is a fairly optimized and lightweight library. Its only dependency is numpy library which is downloaded automatically when you pip install recompy. This feature is useful if you decide to run recompy on server side.

Recompy lets you search parameter space for finding the best model for your data. It keeps best features in memory depending on the test set error. Early stopping is also available. When it is set to an integer, training will be stopped if test set error doesn't improve for the last given epochs.

Current version supports algorithms below:

  • FunkSVD
  • NearestNeighbour
  • NMF
  • SVD++
  • ALS

In upcoming version:

  • Approximate Nearest Neighbors for better performance
  • Framework refactors will come.

Recompy also comes bundled with MovieLens data which consists of 100.000 user, rating pair.

Installation

pip install recompy

Usage

from recompy import load_movie_data, FunkSVD

# get MovieLens data
data = load_movie_data()
# initialization of FunkSVD model
myFunk = FunkSVD()
# training of the model
myFunk.fit(data)

# Create new user. Key:Item ID, Value:Rating
new_user = {'1':5,
            '2':4,
            '4':3}
            
# To find the most similar user resulting from cosine similarity. Recommend 5 items using the most similar user 
myFunk.get_recommendation_for_new_user(new_user, similarity_measure = 'cosine_similarity', 
                                       howManyUsers = 1, howManyItems = 5)

Available Methods for FunkSVD

set_hyperparameters():

A method to set hyperparameters for searching parameter space. Arguments:

initialization_method : How to initialize user and item embeddings

  • random ( default )
  • he
  • normal

max_epoch : Epoch count to train model. Default is 5.
n_latent : Length of user and item embeddings. Default is 10
learning_rate : Learning rate of the model. Default is 0.01
regularization : Regularization rate of the model. DEfault is 0.1
early_stopping : Number of epochs to stop if test error doesn't improve. Default is False.
init_mean : Initialization mean if initialization method is normal.
init_std : Initialization standard deviation if initialization is normal\

fit():

Trains FunkSVD model.Arguments:

data : Training data as numpy array.
test_split : Split data into train and test set. Default is True. test_portion : Portion of test set. Default is 0.10. search_parameter_space : If true, data will not split into train and test sets again.

get_recommendation_for_existing_user():

Gets recommendations for existing user that are not rated by user. Arguments:

user_id : Existing user id

howMany : Count of recommended items to be returned. Default is 10.

get_recommendation_for_new_user():

Gets recommendations for new user depending on given similarity measure. Arguments:

user_ratings : A python dictionary of items and corresponding scores.

similarity_measure : Similarity measures can be:

  • cosine_similarity
  • pearson_correlation
  • adjusted_cosine_similarity
  • weighted_cosine_similarity
  • constrained_pearson_correlation
  • mean_squared_difference ( default )

howManyUsers : Count of most similar users to be used for recommendation. Default is 3

howManyItems : Count of recommended items to be returned. Default is 5.

get_similar_products():

Gets most similar items. Arguments:

item_id : Id of the item.

howMany : Count of similar items to be returned.

Note

This library is created as a part of AI Projects program @ inzva. You can see more at inzva.com

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 87.5%
  • Jupyter Notebook 12.5%