个性化,加权建议 - 排名所有内容 [英] Personalized, Weighted Recommendations - Rank All Content

查看:131
本文介绍了个性化,加权建议 - 排名所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个社交网站的音乐家。我想借歌曲的整个列表从数据库和排名每个人根据其相关的登录的用户。原因之一是,我想在那里总是推荐的10首歌曲,即使用户签约增长45秒前。

I'm building a social site for musicians. I would like to take the whole list of songs from the database and rank each one based on its relevancy to the logged in user. One reason for this is that I'd like there to always be 10 songs recommended, even if the user signed up 45 seconds ago.

我使用的因素有:

  • 歌曲的乐队成员(该网站的所有会的成员,可能都退出曲)
  • 在登录的用户的成员连接(可无)
  • 在歌最近更新(至少会被创造这首歌日)
  • 这首歌的(子)类型(将始终设置)
  • 的用户的(子)类型(将始终设置)

(子)类型属于比较一般的风格,所以我想我既可以重一首歌较高,如果登录用户和歌曲的(子)类型是相同的,或者少一点高,如果他们至少属于到相同的一般类型。

The (sub)genres belong to more general genres, so I figure I can either weight a song higher if the logged in user and the song's (sub)genre are the same, or a little less higher if they at least belong to the same general genre.

我不知道我是否应该瞄准的先验或贝叶斯算法...这似乎是介于两者之间。我有一对夫妇,我已经调整了黑客新闻的算法解释借来的线条。我不太清楚如何把最终结果合力得到我的排名。

I'm not sure if I should be aiming for an Apriori or Bayesian algorithm... It seems to be somewhere in between. I have a couple of lines borrowed from explanations of the Hacker News algorithm that I've tweaked. I'm not quite sure how to put the final results together to get my ranking.

这里的code我写到目前为止,(对于所有意图和目的,工作室是一首的)。我知道在这样的循环查询是不是一个好主意,但我已经做到了这种方式,因为有一些memcaching方案我用,这可能也被批:

Here's the code I've written so far (for all intents and purposes, a studio is a song). I know queries in loops like this are never a good idea, but I've done it this way because there's some memcaching schemes I use and this will probably also be batched:

function studio_relevance($user_id, $user_genre) {
    global $cxn;

$query = "SELECT * FROM studio WHERE project_status='active'";
$result = mysqli_query($cxn, $query) or die($query.': '.mysqli_error($cxn));

$data = array();

while ($studio = mysqli_fetch_object($result)) {
    //Find similarities in social connections and band
    $query_b = "SELECT * FROM band WHERE studio_id=".$studio->studio_id;
    $result_b = mysqli_query($cxn, $query_b) or die($query_b.': '.mysqli_error($cxn));

    $the_band = array();
    while ($people = mysqli_fetch_array($result_b, MYSQLI_ASSOC)) {
        $the_band[] = $people['user_id'];
    }

    $studio_band_count = count($the_band);

    $query = "SELECT * FROM idols WHERE friend_id=".$user_id;
    $result_b = mysqli_query($cxn, $query_b) or die($query_b.': '.mysqli_error($cxn));

    $idol = array();
    while ($people = mysqli_fetch_array($result_b, MYSQLI_ASSOC)) {
        $idol[] = $people['artist_id'];
    }

    $same_band = array_intersect($the_band, $idol);
    $same_band_count = count($same_band);

    ########
    $similar_band = $same_band_count / $studio_band_count;
    ########


    //Find the most recent activity
    $query_b = "SELECT * FROM studio_feed WHERE studio_id=".$studio->studio_id." ORDER BY feed_id DESC LIMIT 1";
    $result_b = mysqli_query($cxn, $query_b) or die($query_b.': '.mysqli_error($cxn));
    $tab = mysqli_fetch_object($result_b);

    $time_diff = strtotime('now') - strtotime($tab->timestamp);
    $hours = $time_diff / 3600;

    ########
    $last_activity = pow(($hours+2), 1.8);
    ########


    //Compare genres
    $genre_weight = 1;

    if ($studio->songGenre == $user_genre) {
        $genre_weight = 3;
    }
    else {
        $query_b = "SELECT * FROM genres";
        $result_b = mysqli_query($cxn, $query_b) or die($query_b.': '.mysqli_error($cxn));

        $genres = array();
        $user_genre_cat = 0;

        while ($genre = mysqli_fetch_object($result_b)) {
            $genres[$genre->genre_cat][] = $genre->genre_id;

            if ($genre->genre_id == $user_genre) {
                $user_genre_cat = $genre->genre_cat;
            }
        } 

        if (in_array($studio->songGenre, $genres[$celeb_cat])) {
            $genre_weight = 2;
        }
    }


    //Find final result
    //$final = $similar_band + $last_activity + $genre_weight;
    //$hours / pow(($similar_band+2), $genre_weight);
}

return $data;
}

任何建议将是极大的AP preciated!我是在正确的轨道,或要对此都错了?

Any suggestions would be greatly appreciated! Am I on the right track or going about this all wrong?

推荐答案

TL;博士。我建议你​​从头开始重写你的问题,或检查出codeReview网站。 HTTP://$c$creview.stackexchange.com/

tl;dr. I'd advise you to rewrite your question from scratch, or check out the CodeReview site. http://codereview.stackexchange.com/

这篇关于个性化,加权建议 - 排名所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆