Пример #1
0
For 10 latent terms, LSE: 82.043269
Starting NMF decomposition with 50 latent features and 100 iterations.
('fit residual', 571.5018)
('total residual', 26.6343)
For 50 latent terms, LSE: 192.148042
Starting NMF decomposition with 100 latent features and 100 iterations.
('fit residual', 378.60300000000001)
('total residual', 23.007999999999999)
For 100 latent terms, LSE: 144.922050
'''

# Que 4 part B

lambda_values = [0.01]
r, w = utility.get_R()
k = 10
truePos = 0
falsePos = 0
falseNeg = 0
precisionArray = []
recallArray = []
rows, cols = r.shape
threshold_ranges = [x / 10.0 for x in range(0, 50, 5)]

# Run Regularized ALS for different values of lambda
for lambda_val in lambda_values:
    uv = utility.weightedRegALS(r, lambda_val, k, w, 20)
    for threshold in threshold_ranges:
        for i in range(len(r)):
            for j in range(len(r[i])):
Пример #2
0
                            key=lambda abc: weighted_list[abc])[-N:]
        top_n_matrix[i] = copy.copy(top_n_list)

    return top_n_matrix


# Que 5 part A

# find out top L movies from uv for each user (each row) & find average precision
# Uses 10-fold cross validation

#r, w = utility.get_R()

K_VALUE = 10
L = 5
r = utility.get_R()
lambda_val = 0.1
k = 100
n_iter = 20

kf = KFold(100000, 10, True)
fold_precision = 0

for train, test in kf:
    #    test_index += 1
    #    local_error = 0

    r, w, test_rows = utility.r_skiplist(test)
    test_matrix = utility.get_matrix_from_data(test_rows)
    # use Reg ALS matrix
    #u, v = utility.nmf(w, K_VALUE, r)   # Swap R & W
Пример #3
0
For 10 latent terms, LSE: 82.043269
Starting NMF decomposition with 50 latent features and 100 iterations.
('fit residual', 571.5018)
('total residual', 26.6343)
For 50 latent terms, LSE: 192.148042
Starting NMF decomposition with 100 latent features and 100 iterations.
('fit residual', 378.60300000000001)
('total residual', 23.007999999999999)
For 100 latent terms, LSE: 144.922050
'''


# Que 4 part B

lambda_values = [0.01]
r, w = utility.get_R()
k = 10
truePos = 0;
falsePos = 0;
falseNeg = 0;
precisionArray = []
recallArray = []
rows,cols = r.shape
threshold_ranges = [x/10.0 for x in range(0, 50, 5)]

# Run Regularized ALS for different values of lambda
for lambda_val in lambda_values:
    uv = utility.weightedRegALS(r, lambda_val, k, w, 20)
    for threshold in threshold_ranges:
        for i in range(len(r)):
            for j in range(len(r[i])):
Пример #4
0
        #top_n_list = numpy.argpartition(weighted_list, -N)[-N:]
        top_n_list = sorted(range(len(weighted_list)), key=lambda abc: weighted_list[abc])[-N:]
        top_n_matrix[i] = copy.copy(top_n_list)

    return top_n_matrix

# Que 5 part A

# find out top L movies from uv for each user (each row) & find average precision
# Uses 10-fold cross validation

#r, w = utility.get_R()

K_VALUE = 10
L = 5
r = utility.get_R()
lambda_val = 0.1
k = 100
n_iter = 20

kf = KFold(100000, 10, True)
fold_precision = 0

for train, test in kf:
#    test_index += 1
#    local_error = 0

    r, w, test_rows = utility.r_skiplist(test)
    test_matrix = utility.get_matrix_from_data(test_rows)
    # use Reg ALS matrix
    #u, v = utility.nmf(w, K_VALUE, r)   # Swap R & W