def example():
    """simple test and performance measure
    """
    num_user, num_item, ratings = load_ml_1m()
    # suffle_data
    np.random.shuffle(ratings)

    # split data to training & validation
    train_pct = 0.9
    train_size = int(train_pct * len(ratings))
    train = ratings[:train_size]
    validation = ratings[train_size:]

    # params
    num_feature = 10
    bmf_model = BayesianMatrixFactorization(num_user,
                                            num_item,
                                            num_feature,
                                            train,
                                            validation,
                                            max_rating=5,
                                            min_rating=1)

    start_time = time.clock()
    bmf_model.estimate(5)
    end_time = time.clock()
    print "time spend = %.3f" % (end_time - start_time)

    return bmf_model
def example():
    """simple test and performance measure
    """

    num_user, num_item, ratings = load_ml_1m()
    # suffle_data
    np.random.shuffle(ratings)

    # split data to training & validation
    train_pct = 0.9
    train_size = int(train_pct * len(ratings))
    train = ratings[:train_size]
    validation = ratings[train_size:]

    # params
    num_feature = 10
    mf_model = MatrixFactorization(
        num_user, num_item, num_feature, train, validation, max_rating=5, min_rating=1, batch_size=100000
    )

    start_time = time.clock()
    mf_model.estimate(5)
    end_time = time.clock()
    print "time spend = %.3f" % (end_time - start_time)

    return mf_model
Beispiel #3
0
    def setUp(self):
        num_user, num_item, ratings = load_ml_1m()
        np.random.shuffle(ratings)
        self.num_user = num_user
        self.num_item = num_item
        self.ratings = ratings
        self.num_feature = 10

        train_pct = 0.9
        train_size = int(train_pct * len(self.ratings))
        self.train = self.ratings[:train_size]
        self.validation = self.ratings[train_size:]
import numpy as np

from load_data import load_ml_1m, load_rating_matrix
from matrix_factorization import MatrixFactorization
from evaluation_metrics import RMSE
#from mf.bayesian_matrix_factorization import BayesianMatrixFactorization


if __name__ == "__main__":

    # load MovieLens data
    num_user, num_item, ratings = load_ml_1m()
    np.random.shuffle(ratings)

    # set feature numbers
    num_feature = 10

    # set max_iterations
    max_iter = 20

    # split data to training & testing
    train_pct = 0.9
    train_size = int(train_pct * len(ratings))
    train = ratings[:train_size]
    validation = ratings[train_size:]

    # models
    rec = MatrixFactorization(num_user, num_item, num_feature, train, validation, max_rating=5, min_rating=1)

    # fitting
    rec.estimate(max_iter)