示例#1
0
文件: rbm.py 项目: RafaelaWu/01.104
def predictForUser(user, W, training, predictType="exp"):
    ### TO IMPLEMENT
    # given a user ID, predicts all movie ratings for the user
    return [
        predictMovieForUser(movie, user, W, training, predictType=predictType)
        for movie in lib.getUsefulStats(training)["u_movies"]
    ]
示例#2
0
def predictForUser(user, W, training, predictType="exp"):

    trStats = lib.getUsefulStats(training)
    # print(trStats["u_movies"])

    return [
        predictMovieForUser(movie, user, W, training, predictType)
        for movie in trStats["u_movies"]
    ]
示例#3
0
def predictForUser(user, W, training, predictType="exp"):
    ### TO IMPLEMENT
    # given a user ID, predicts all movie ratings for the user

    # similar to the above predict function but just for 1 user.
    return [
        predictMovieForUser(movie, user, W, training, predictType=predictType)
        for movie in lib.getUsefulStats(training)["u_movies"]
    ]
示例#4
0
def predictForUser(user, W, training, predictType="exp"):
    ### TO IMPLEMENT
    # given a user ID, predicts all movie ratings for the user
    trainingStats = lib.getUsefulStats(training)
    user_ratings = []
    for movie in trainingStats:
        user_ratings.append(
            predictMovieForUser(movie, user, W, training, predictType))
    return np.array(user_ratings)
示例#5
0
def predictForUser(user, W, training, predictType="exp"):
    ### TO IMPLEMENT
    # given a user ID, predicts all movie ratings for the user
    ###########################################################################
    #                             START OF YOUR CODE                          #
    ###########################################################################
    all_movies = lib.getUsefulStats(training)["u_movies"]
    movies_pred = []
    for movie in all_movies:
        pred = predictMovieForUser(movie, user, W, training, predictType=predictType)
        movies_pred.append(pred)    
    return movies_pred
示例#6
0
import numpy as np
import rbm
import projectLib as lib
import pickle

training = lib.getTrainingData()
validation = lib.getValidationData()
# You could also try with the chapter 4 data
# training = lib.getChapter4Data()

trStats = lib.getUsefulStats(training)
vlStats = lib.getUsefulStats(validation)

K = 5

# SET PARAMETERS HERE!!!
# number of hidden units
# F = 10
epochs = 30
# gradientLearningRate = 0.1

# file for past trained data
fileName = 'best_W'

try:
    # try to load existing trained weight, if any
    best_W = pickle.load(open(fileName, 'rb'))
except:
    # otherwise, train/tune

    ## Parameter to tune
示例#7
0
import numpy as np
import rbm
import projectLib as lib
import pickle

training = lib.getTrainingData()
validation = lib.getValidationData()
# You could also try with the chapter 4 data
# training = lib.getChapter4Data()

trStats = lib.getUsefulStats(training)
vlStats = lib.getUsefulStats(validation)

K = 5

# mode = 'batch'
mode = 'single'

finalW = np.zeros([5,5,5])
finalRMSE = 100

def run_RBM(F, epochs, epsilon, B, weightcost, momentum, f, mode):
    # Initialise all our arrays
    W = rbm.getInitialWeights(trStats["n_movies"], F, K)
    bestW = np.zeros(W.shape)
    bestRMSE = 100

    posprods = np.zeros(W.shape)
    negprods = np.zeros(W.shape)
    grad = np.zeros(W.shape)