# 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])): if (uv[i, j] >= threshold): if (r[i, j] >= threshold): truePos += 1 else: falsePos += 1 else: if (r[i, j] >= threshold): #if(uv[i, j] < threshold): falseNeg += 1 print 'Precision for threshold: %f' % threshold pre = float(truePos) / float(truePos + falsePos)
# Que 5 part B # hit-rate is assumed to be precision # failure rate is total - precision r, w = utility.get_R() L = 5 lambda_val = 0.1 k = 100 n_iter = 20 hit_rate_list = [] false_alarm_list = [] recall_list = [] # replace this with RegALS( ) #u, v = utility.nmf(w, K_VALUE, r) # Swap R & W #uv = numpy.dot(u, v) uv = utility.weightedRegALS(w, lambda_val, k, r, n_iter) for i in range(1, L + 1): top_l_orig_matrix = gettopN(r, i, w) top_l_predict_matrix = gettopN(uv, i, w) hit_rate, false_alarm = get_mean_precision(top_l_orig_matrix, top_l_predict_matrix) print "iteration" print i print "hit rate" print hit_rate hit_rate_list.append(hit_rate) false_alarm_list.append(false_alarm) # Plot false alarm rate vs hit-rate
# 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])): if(uv[i, j] >= threshold): if(r[i, j] >= threshold): truePos += 1 else: falsePos += 1 else: if(r[i, j] >= threshold): #if(uv[i, j] < threshold): falseNeg += 1 print 'Precision for threshold: %f' %threshold pre = float (truePos) / float (truePos + falsePos) print pre
# Que 5 part B # hit-rate is assumed to be precision # failure rate is total - precision r, w = utility.get_R() L = 5 lambda_val = 0.1 k = 100 n_iter = 20 hit_rate_list = [] false_alarm_list = [] recall_list = [] # replace this with RegALS( ) #u, v = utility.nmf(w, K_VALUE, r) # Swap R & W #uv = numpy.dot(u, v) uv = utility.weightedRegALS(w, lambda_val, k, r, n_iter) for i in range(1, L+1): top_l_orig_matrix = gettopN(r, i, w) top_l_predict_matrix = gettopN(uv, i, w) hit_rate, false_alarm = get_mean_precision(top_l_orig_matrix, top_l_predict_matrix) print "iteration" print i print "hit rate" print hit_rate hit_rate_list.append(hit_rate) false_alarm_list.append(false_alarm) # Plot false alarm rate vs hit-rate