예제 #1
0
def vector_score_function(user_id, item_id, star=0):
    "tfidf and vector model with different predictors"
    if user_id in user_matrix and item_id in item_matrix:
        mf_score = cal_score(user_id, item_id, user_matrix, item_matrix,
                             user_bias, item_bias, global_bias)
        lr_score = vec_predictor.predict(user_id, item_id)
        if type(lr_score) != float:
            raise Exception('predictor return type error')
        print '%s\t%s\t%lf\t%lf\t%lf\t%lf\t%lf' % (
            user_id, item_id, mf_score, lr_score, star,
            star - mf_score - lr_score, star - mf_score)
        #return cal_score(user_id, item_id, user_matrix, item_matrix, user_bias, item_bias, global_bias) + tfidf_predictor.predict(user_id, item_id)
        return mf_score + lr_score
    elif user_id in user_matrix:
        global user_miss
        user_miss += 1
        return user_score[user_id]['score'] * 1.0 / user_score[user_id]['count']
    elif item_id in item_matrix:
        global item_miss
        item_miss += 1
        return item_score[item_id]['score'] * 1.0 / item_score[item_id]['count']
    else:
        global all_miss
        all_miss += 1
        #return random.randint(1, 5)
        return 0
예제 #2
0
def vector_score_function(user_id, item_id, star=0):
    "tfidf and vector model with different predictors"
    if user_id in user_matrix and item_id in item_matrix:
        mf_score = cal_score(user_id, item_id, user_matrix, item_matrix, user_bias, item_bias, global_bias)
        lr_score = vec_predictor.predict(user_id, item_id)
        if type(lr_score) != float:
            raise Exception("predictor return type error")
        print "%s\t%s\t%lf\t%lf\t%lf\t%lf\t%lf" % (
            user_id,
            item_id,
            mf_score,
            lr_score,
            star,
            star - mf_score - lr_score,
            star - mf_score,
        )
        # return cal_score(user_id, item_id, user_matrix, item_matrix, user_bias, item_bias, global_bias) + tfidf_predictor.predict(user_id, item_id)
        return mf_score + lr_score
    elif user_id in user_matrix:
        global user_miss
        user_miss += 1
        return user_score[user_id]["score"] * 1.0 / user_score[user_id]["count"]
    elif item_id in item_matrix:
        global item_miss
        item_miss += 1
        return item_score[item_id]["score"] * 1.0 / item_score[item_id]["count"]
    else:
        global all_miss
        all_miss += 1
        # return random.randint(1, 5)
        return 0
예제 #3
0
def mf_score_function(user_id, item_id, star=0):
    if user_id in user_matrix and item_id in item_matrix:
        return cal_score(user_id, item_id, user_matrix, item_matrix, user_bias, item_bias, global_bias)
    elif user_id in user_matrix:
        global user_miss
        user_miss += 1
        return user_score[user_id]["score"] * 1.0 / user_score[user_id]["count"]
    elif item_id in item_matrix:
        global item_miss
        item_miss += 1
        return item_score[item_id]["score"] * 1.0 / item_score[item_id]["count"]
    else:
        global all_miss
        all_miss += 1
        return 0
예제 #4
0
def mf_score_function(user_id, item_id, star=0):
    if user_id in user_matrix and item_id in item_matrix:
        return cal_score(user_id, item_id, user_matrix, item_matrix, user_bias,
                         item_bias, global_bias)
    elif user_id in user_matrix:
        global user_miss
        user_miss += 1
        return user_score[user_id]['score'] * 1.0 / user_score[user_id]['count']
    elif item_id in item_matrix:
        global item_miss
        item_miss += 1
        return item_score[item_id]['score'] * 1.0 / item_score[item_id]['count']
    else:
        global all_miss
        all_miss += 1
        return 0
예제 #5
0
def vector_score_function(user_id, item_id, star = 0):
    "tfidf and vector model with different predictors"
    if user_id in user_matrix and item_id in item_matrix:
        mf_score = cal_score(user_id, item_id, user_matrix, item_matrix, user_bias, item_bias, global_bias)
        lr_score = vec_predictor.predict(user_id, item_id)
        #return cal_score(user_id, item_id, user_matrix, item_matrix, user_bias, item_bias, global_bias) + tfidf_predictor.predict(user_id, item_id)
        return mf_score + lr_score
    elif user_id in user_matrix:
        global user_miss
        user_miss += 1
        return user_score[user_id]['score'] * 1.0 / user_score[user_id]['count']
    elif item_id in item_matrix:
        global item_miss
        item_miss += 1
        return item_score[item_id]['score'] * 1.0 / item_score[item_id]['count']
    else:
        global all_miss
        all_miss += 1
        #return random.randint(1, 5)
        return 0
예제 #6
0
def mf_score_function(user_id, item_id, star = 0):
    if user_id in user_matrix and item_id in item_matrix:
        mf_score = cal_score(user_id, item_id, user_matrix, item_matrix, user_bias, item_bias, global_bias)
        residual_score = 0.0
        if user_id in user_vec:
            residual_score += np.dot(user_vec[user_id], user_weight)
        if item_id in item_vec:
            residual_score += np.dot(item_vec[item_id], item_weight)
        return mf_score + residual_score
    elif user_id in user_matrix:
        global user_miss
        user_miss += 1
        return user_score[user_id]['score'] * 1.0 / user_score[user_id]['count']
    elif item_id in item_matrix:
        global item_miss
        item_miss += 1
        return item_score[item_id]['score'] * 1.0 / item_score[item_id]['count']
    else:
        global all_miss
        all_miss += 1
        return 0
예제 #7
0
def vector_score_function(user_id, item_id, star=0):
    "tfidf and vector model with different predictors"
    if user_id in user_matrix and item_id in item_matrix:
        mf_score = cal_score(user_id, item_id, user_matrix, item_matrix,
                             user_bias, item_bias, global_bias)
        lr_score = vec_predictor.predict(user_id, item_id)
        #return cal_score(user_id, item_id, user_matrix, item_matrix, user_bias, item_bias, global_bias) + tfidf_predictor.predict(user_id, item_id)
        return mf_score + lr_score
    elif user_id in user_matrix:
        global user_miss
        user_miss += 1
        return user_score[user_id]['score'] * 1.0 / user_score[user_id]['count']
    elif item_id in item_matrix:
        global item_miss
        item_miss += 1
        return item_score[item_id]['score'] * 1.0 / item_score[item_id]['count']
    else:
        global all_miss
        all_miss += 1
        #return random.randint(1, 5)
        return 0