zero package¶
Subpackages¶
Submodules¶
zero.als module¶
- class zero.als.MangakiALS(nb_components=20, nb_iterations=40, lambda_=0.1, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
Alternating Least Squares \(r_{ij} - mean_i = u_i^T v_j\) Ratings are preprocessed by removing the mean rating of each user Then \(u_i\) and \(v_j\) are updated alternatively, using the least squares estimator (closed form)
ALS: Zhou, Yunhong, et al. “Large-scale parallel collaborative filtering for the netflix prize.” International Conference on Algorithmic Applications in Management. Springer, Berlin, Heidelberg, 2008. http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.173.2797&rep=rep1&type=pdf
Implemented by Pierre Vigier, JJ Vie
- property is_serializable¶
zero.als2 module¶
- class zero.als2.MangakiALS2(nb_components=20, nb_iterations=40, lambda_=0.1, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
Alternating Least Squares for “Singular Value Decomposition” model (aka latent factor model) \(r_{ij} - mean = bias_i + bias_j + u_i^T v_j\) Modified version of ALS for the SVD model Ratings are preprocessed by removing the overall mean Then (\(u_i\) and \(bias_i\)), (\(v_j\) and \(bias_j\)) are updated alternatively in closed form
ALS: Zhou, Yunhong, et al. “Large-scale parallel collaborative filtering for the netflix prize.” International Conference on Algorithmic Applications in Management. Springer, Berlin, Heidelberg, 2008. http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.173.2797&rep=rep1&type=pdf
SVD: Koren, Yehuda, and Robert Bell. “Advances in collaborative filtering.” Recommender systems handbook. Springer, Boston, MA, 2015. 77-118. https://pdfs.semanticscholar.org/6800/fbe3314be9f638fb075e15b489d1aadb3030.pdf
- property is_serializable¶
zero.als3 module¶
- class zero.als3.MangakiALS3(nb_components=20, nb_iterations=20, lambda_=0.1, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
Alternating Least Squares for “Singular Value Decomposition” model (aka latent factor model)
This implementation was supposed to be shorter and easier to read than MangakiALS2, but the performance is slightly worse, maybe because the initialization is different. (Gaussian instead of uniform; but Zhou’s paper suggested a Gaussian initialization)
- property is_serializable¶
zero.balse module¶
zero.cfm module¶
zero.chrono module¶
zero.dataset module¶
- class zero.dataset.AnonymizedData(X, y, y_text, nb_users, nb_works)¶
Bases:
tuple
- X¶
Alias for field number 0
- nb_users¶
Alias for field number 3
- nb_works¶
Alias for field number 4
- y¶
Alias for field number 1
- y_text¶
Alias for field number 2
zero.efa module¶
- class zero.efa.MangakiEFA(NB_COMPONENTS=20, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
Factor Analysis: See http://scikit-learn.org/stable/modules/decomposition.html#factor-analysis Better way to get interpretable components, see MangakiNMF
zero.fma module¶
zero.gbr module¶
zero.knn module¶
- class zero.knn.MangakiKNN(nb_neighbors=20, rated_by_neighbors_at_least=3, missing_is_mean=True, weighted_neighbors=False, nb_iterations=None, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
- property is_serializable¶
zero.knn0 module¶
zero.knn2 module¶
- class zero.knn2.MangakiKNN2(nb_neighbors=20, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
Toy implementation (not usable in production) of KNN for the mere sake of science. \(N\) users, \(M\) ~ 10k works, \(P\) ~ 300k user-work pairs, \(K\) neighbors.
Algorithm: For each user-work pair (over all P pairs): - Find closest raters of user who rated this work (takes \(O(M \log M)\)) - Compute their average rating (takes \(O(K)\)) Complexity: \(O(P (M \log M + K))\) => Oops!
- property is_serializable¶
zero.lasso module¶
- class zero.lasso.MangakiLASSO(with_bias=True, alpha=0.01, T=None, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
zero.lasso0 module¶
zero.nmf module¶
zero.pca module¶
zero.recommendation_algorithm module¶
- class zero.recommendation_algorithm.RecommendationAlgorithm(metrics=None, verbose_level=1)[source]¶
Bases:
object
- compute_dcg(y_pred, y_true)[source]¶
Computes the discounted cumulative gain as stated in: https://gist.github.com/bwhite/3726239
- factory = <zero.recommendation_algorithm.RecommendationAlgorithmFactory object>¶
- property is_serializable¶
- load(folder, filename=None)[source]¶
This function raises FileNotFoundException if no backup exists.
- recommend(user_ids, extra_users_parameters=None, item_ids=None, k=None, method='mean')[source]¶
Recommend \(k\) items to a group of users.
- Parameters:
user_ids – the users that are in the dataset of this algorithm.
extra_users_parameters – the parameters for users that weren’t.
item_ids – a subset of items. If is it None, then it is all items.
k – the number of items to recommend, if None then it is all items.
method – a way to combine the predictions. By default it is mean.
- Returns:
a numpy array with two columns, item_id and recommendation score
- Complexity:
\(O(N + K \log K)\)
zero.sgd module¶
- class zero.sgd.MangakiSGD(nb_components=20, nb_iterations=40, gamma=0.01, lambda_=0.1, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
- property is_serializable¶
zero.sgd0 module¶
zero.sgd2 module¶
- class zero.sgd2.MangakiSGD2(nb_components=20, nb_iterations=10, gamma=0.01, lambda_=0.1, batches=400, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
- property is_serializable¶
zero.side module¶
zero.ssvd module¶
zero.svd module¶
Mangaki sparse SVD. Author: Jill-Jênn Vie, 2020
- class zero.svd.MangakiSVD(nb_components=20, nb_iterations=None, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
Implementation of SVD with sparse matrices. It does not compute the whole matrix for recommendations but the production must be able to do sparse matrix operations effectively. It is 7x faster than svd1.py, and it only relies on numpy/scipy.
- property is_serializable¶
Check whether we can save the model.
zero.svd2 module¶
Mangaki sparse SVD. Author: Jill-Jênn Vie, 2020
- class zero.svd2.MangakiSVD2(nb_components=20, nb_iterations=None, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
Implementation of SVD with sparse matrices. It does not compute the whole matrix for recommendations but the production should be able to do sparse matrix operations effectively. It is 7x faster than svd.py, and it only relies on numpy/scipy.
- property is_serializable¶
Check whether we can save the model.
zero.values module¶
zero.wals module¶
zero.xals module¶
- class zero.xals.MangakiXALS(nb_components=10, nb_iterations=10, lambda_=0.1, *args, **kwargs)[source]¶
Bases:
zero.recommendation_algorithm.RecommendationAlgorithm
- property is_serializable¶