Table Of Contents

This Page

mrec.mf Package

wrmf Module

Weighted Regularize Matrix Factorization by alternating least squares.

See: Y. Hu, Y. Koren and C. Volinsky, Collaborative filtering for implicit feedback datasets, ICDM 2008. http://research.yahoo.net/files/HuKorenVolinsky-ICDM08.pdf R. Pan et al., One-class collaborative filtering, ICDM 2008. http://www.hpl.hp.com/techreports/2008/HPL-2008-48R1.pdf

class mrec.mf.wrmf.WRMFRecommender(d, alpha=1, lbda=0.015, num_iters=15)

Bases: mrec.mf.recommender.MatrixFactorizationRecommender

Parameters :

d : int

Number of latent factors.

alpha : float

Confidence weight, confidence c = 1 + alpha*r where r is the observed “rating”.

lbda : float

Regularization constant.

num_iters : int

Number of iterations of alternating least squares.

Methods

batch_recommend_items(dataset[, max_items, ...]) Recommend new items for all users in the training dataset.
fit(train[, item_features]) Learn factors from training set.
init_factors(num_factors[, assign_values])
load(filepath) Load a recommender model from file after it has been serialized with save().
load_factors(user_factor_filepath, ...) Load precomputed user and item factors from file.
predict_ratings([users, item_features]) Predict ratings/scores for all items for supplied users.
range_recommend_items(dataset, user_start, ...) Recommend new items for a range of users in the training dataset.
read_recommender_description(filepath) Read a recommender model description from file after it has been saved by save(), without loading any additional associated data into memory.
recommend_items(dataset, u[, max_items, ...]) Recommend up to max_items most highly recommended items for user u.
save(filepath) Serialize model to file.
update(indices, H, HH) Update latent factors for a single user or item.
fit(train, item_features=None)

Learn factors from training set. User and item factors are fitted alternately.

Parameters :

train : scipy.sparse.csr_matrix or mrec.sparse.fast_sparse_matrix

User-item matrix.

item_features : array_like, shape = [num_items, num_features]

Features for each item in the dataset, ignored here.

init_factors(num_factors, assign_values=True)
update(indices, H, HH)

Update latent factors for a single user or item.

mrec.mf.wrmf.main()

warp Module

class mrec.mf.warp.WARPMFRecommender(d, gamma, C, batch_size=10, positive_thresh=1e-05, max_trials=50)

Bases: mrec.mf.recommender.MatrixFactorizationRecommender

Learn matrix factorization optimizing the WARP loss.

Parameters :

d : int

Dimensionality of factors.

gamma : float

Learning rate.

C : float

Regularization constant.

batch_size : int

Mini batch size for SGD updates.

positive_thresh: float :

Consider an item to be “positive” i.e. liked if its rating is at least this.

max_trials : int

Number of attempts allowed to find a violating negative example during updates. In practice it means that we optimize for ranks 1 to max_trials-1.

Methods

batch_recommend_items(dataset[, max_items, ...]) Recommend new items for all users in the training dataset.
create_validation_set(train) Hide and return half of the known items for a sample of users, and estimate the number of sgd iterations to run.
fit(train[, item_features]) Learn factors from training set.
load(filepath) Load a recommender model from file after it has been serialized with save().
load_factors(user_factor_filepath, ...) Load precomputed user and item factors from file.
predict_ratings([users, item_features]) Predict ratings/scores for all items for supplied users.
range_recommend_items(dataset, user_start, ...) Recommend new items for a range of users in the training dataset.
read_recommender_description(filepath) Read a recommender model description from file after it has been saved by save(), without loading any additional associated data into memory.
recommend_items(dataset, u[, max_items, ...]) Recommend up to max_items most highly recommended items for user u.
save(filepath) Serialize model to file.
create_validation_set(train)

Hide and return half of the known items for a sample of users, and estimate the number of sgd iterations to run.

Parameters :

train : scipy.sparse.csr_matrix

User-item matrix.

Returns :

max_iters : int

Total number of sgd iterations to run.

validation_iters : int

Check progress after this many iterations.

validation : dict

Validation set.

fit(train, item_features=None)

Learn factors from training set.

Parameters :

train : scipy.sparse.csr_matrix

User-item matrix.

item_features : array_like, shape = [num_items, num_features]

Features for each item in the dataset, ignored here.

mrec.mf.warp.main()

warp2 Module

class mrec.mf.warp2.WARP2MFRecommender(d, gamma, C, batch_size=10, positive_thresh=1e-05, max_trials=50)

Bases: mrec.mf.warp.WARPMFRecommender

Learn matrix factorization optimizing the WARP loss with item features as well as user-item training data.

Parameters :

d : int

Dimensionality of factors.

gamma : float

Learning rate.

C : float

Regularization constant.

batch_size : int

Mini batch size for SGD updates.

positive_thresh: float :

Consider an item to be “positive” i.e. liked if its rating is at least this.

max_trials : int

Number of attempts allowed to find a violating negative example during updates. In practice it means that we optimize for ranks 1 to max_trials-1.

Methods

batch_recommend_items(dataset[, max_items, ...]) Recommend new items for all users in the training dataset.
create_validation_set(train) Hide and return half of the known items for a sample of users, and estimate the number of sgd iterations to run.
fit(train[, item_features]) Learn factors from training set and item features.
load(filepath) Load a recommender model from file after it has been serialized with save().
load_factors(user_factor_filepath, ...) Load precomputed user and item factors from file.
predict_ratings([users, item_features]) Predict ratings/scores for all items for supplied users.
range_recommend_items(dataset, user_start, ...) Recommend new items for a range of users in the training dataset.
read_recommender_description(filepath) Read a recommender model description from file after it has been saved by save(), without loading any additional associated data into memory.
recommend_items(dataset, u[, max_items, ...]) Recommend up to max_items most highly recommended items for user u.
save(filepath) Serialize model to file.
fit(train, item_features=None)

Learn factors from training set and item features.

Parameters :

train : scipy.sparse.csr_matrix

User-item matrix.

item_features : array_like, shape = [num_items, num_features]

Features for each item in the dataset.

predict_ratings(users=None, item_features=None)

Predict ratings/scores for all items for supplied users. Assumes you’ve already called fit() to learn the factors.

Only call this if you really want predictions for all items. To get the top-k recommended items for each user you should call one of the recommend_items() instead.

Parameters :

users : int or array-like

Index or indices of users for which to make predictions.

item_features : array_like, shape = [num_items, num_features]

Features for each item in the dataset.

Returns :

predictions : numpy.ndarray, shape = [len(users), num_items]

Predicted ratings for all items for each supplied user.

mrec.mf.warp2.main(file_format, filepath, feature_format, feature_file, outfile)