{"id":3242,"date":"2022-02-27T13:47:36","date_gmt":"2022-02-27T05:47:36","guid":{"rendered":"https:\/\/egonlin.com\/?p=3242"},"modified":"2022-02-27T13:47:36","modified_gmt":"2022-02-27T05:47:36","slug":"%e7%ac%ac%e4%b8%80%e8%8a%82%ef%bc%9a%e6%8e%a8%e8%8d%90%e7%b3%bb%e7%bb%9f%e5%b8%b8%e7%94%a8%e8%af%84%e4%bc%b0%e6%8c%87%e6%a0%87","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=3242","title":{"rendered":"\u7b2c\u4e00\u8282\uff1a\u63a8\u8350\u7cfb\u7edf\u5e38\u7528\u8bc4\u4f30\u6307\u6807"},"content":{"rendered":"<h1>\u63a8\u8350\u7cfb\u7edf\u5e38\u7528\u8bc4\u4f30\u6307\u6807<\/h1>\n<h1>RMSE<\/h1>\n<p>&emsp;&emsp;\u52a0\u5927\u4e86\u5bf9\u9884\u6d4b\u4e0d\u51c6\u7684\u7528\u6237\u7269\u54c1\u8bc4\u5206\u7684\u60e9\u7f5a\u3002<\/p>\n<p>$$<br \/>\n\\text{RMSE}=\\sqrt\\frac{\\sum<em>{u,i\\in{T}}(r<\/em>{ui}-\\hat{r_{ui}})^2}{|T|}<br \/>\n$$<\/p>\n<pre><code class=\"language-python\"># records[i] = [u,i,rui,pui] # rui\u662f\u7528\u6237u\u5bf9\u7269\u54c1i\u7684\u5b9e\u9645\u8bc4\u5206\uff0cpui\u662f\u7528\u6237u\u5bf9\u7269\u54c1i\u7684\u9884\u6d4b\u8bc4\u5206\n\ndef rmse(records):\n    &quot;&quot;&quot;\u8ba1\u7b97\u5747\u65b9\u6839\u8bef\u5dee&quot;&quot;&quot;\n\n    return math.sqrt(sum([(rui-pui)*(rui-pui) for u,i,rui,pui in records])\/len(records))<\/code><\/pre>\n<h1>MAE<\/h1>\n<p>&emsp;&emsp;\u5982\u679c\u8bc4\u5206\u7cfb\u7edf\u662f\u57fa\u4e8e\u6574\u6570\u5efa\u7acb\u7684\uff0c\u5bf9\u9884\u6d4b\u7ed3\u679c\u53d6\u6574\u4f1a\u964d\u4f4eMAE\u7684\u8bef\u5dee\u3002<\/p>\n<p>$$<br \/>\n\\text{MAE}=\\frac{\\sum<em>{u,i\\in{T}}|r<\/em>{ui}-\\hat{r_{ui}}|}{|T|}<br \/>\n$$<\/p>\n<pre><code class=\"language-python\"># records[i] = [u,i,rui,pui] # rui\u662f\u7528\u6237u\u5bf9\u7269\u54c1i\u7684\u5b9e\u9645\u8bc4\u5206\uff0cpui\u662f\u7528\u6237u\u5bf9\u7269\u54c1i\u7684\u9884\u6d4b\u8bc4\u5206\n\ndef mae(records):\n    &quot;&quot;&quot;\u8ba1\u7b97\u5e73\u5747\u7edd\u5bf9\u8bef\u5dee&quot;&quot;&quot;\n\n    return math.sqrt(sum([abs(rui-pui) for u,i,rui,pui in records])\/len(records))<\/code><\/pre>\n<h1>Precision(\u51c6\u786e\u7387)&amp;Recall(\u53ec\u56de\u7387)<\/h1>\n<p>$$<br \/>\n\\text{Precision}=\\frac{\\sum<em>{u\\in{U}}|R(u)\\bigcap{T(u)}|}{\\sum<\/em>{u\\in{U}}|R(u)|}<br \/>\n$$<br \/>\n\u5176\u4e2d$R(u)$\u662f\u7528\u6237\u5728\u8bad\u7ec3\u96c6\u4e0a\u7684\u884c\u4e3a\u7ed9\u7528\u6237\u4f5c\u51fa\u7684\u63a8\u8350\u5217\u8868\u3002<\/p>\n<p>$$<br \/>\n\\text{Recall}=\\frac{\\sum<em>{u\\in{U}}|R(u)\\bigcap{T(u)}|}{\\sum<\/em>{u\\in{U}}|T(u)|}<br \/>\n$$<br \/>\n\u5176\u4e2d$T(u)$\u662f\u7528\u6237\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684\u884c\u4e3a\u7ed9\u7528\u6237\u4f5c\u51fa\u7684\u63a8\u8350\u5217\u8868\u3002<\/p>\n<pre><code class=\"language-python\">def precision_recall(test, N):\n    &quot;&quot;&quot;\n    \u8ba1\u7b97\u51c6\u786e\u7387\u548c\u53ec\u56de\u7387\n    test: \n    N: \u63a8\u8350\u5217\u8868\u957f\u5ea6\n    &quot;&quot;&quot;\n    hit = 0\n    n_recall = 0\n    n_precision = 0\n\n    for user, item in test.items():\n        rank = Recommend(user, N)\n        hit += lenn(rank &amp; itmes)\n        n_recall += len(items)\n        n_precision += N\n\n    return [hit\/(1.*n_recall), hit\/(1.*n_precision)]<\/code><\/pre>\n<h1>\u8986\u76d6\u7387<\/h1>\n<p>&emsp;&emsp;\u8986\u76d6\u7387\u63cf\u8ff0\u4e00\u4e2a\u63a8\u8350\u7cfb\u7edf\u5bf9\u7269\u54c1\u957f\u5c3e\u7684\u53d1\u6398\u80fd\u529b\u3002<\/p>\n<p>$$<br \/>\n\\text{Coverate}=\\frac{|\\bigcup_{u\\in{U}}R(u)|}{I}<br \/>\n$$<br \/>\n\u5176\u4e2d$R(u)$\u662f\u63a8\u8350\u7cfb\u7edf\u7ed9\u6bcf\u4e2a\u7528\u6237\u63a8\u8350\u4e00\u4e2a\u957f\u5ea6\u4e3a$N$\u7684\u7269\u54c1\u5217\u8868\u3002<\/p>\n<h1>\u4fe1\u606f\u71b5<\/h1>\n<p>&emsp;&emsp;\u4fe1\u606f\u71b5\u53ef\u4ee5\u5b9a\u4e49\u8986\u76d6\u7387\u3002<\/p>\n<p>$$<br \/>\nH=\\sum_{i=1}^np(i)\\log{p(i)}<br \/>\n$$<br \/>\n\u5176\u4e2d$p(i)$\u662f\u7269\u54c1$i$\u7684\u6d41\u884c\u5ea6\u9664\u4ee5\u6240\u6709\u7269\u54c1\u6d41\u884c\u5ea6\u4e4b\u548c\u3002<\/p>\n<h1>\u57fa\u5c3c\u7cfb\u6570<\/h1>\n<p>&emsp;&emsp;\u57fa\u5c3c\u7cfb\u6570\u53ef\u4ee5\u5b9a\u4e49\u8986\u76d6\u7387\u3002\u57fa\u5c3c\u7cfb\u6570\u4e5f\u53ef\u4ee5\u67e5\u770b\u63a8\u8350\u7cfb\u7edf\u7b97\u6cd5\u662f\u5426\u5177\u6709\u9a6c\u592a\u6548\u5e94\uff08\u6d41\u884c\u66f4\u6d41\u884c\uff0c\u4e0d\u6d41\u884c\u66f4\u4e0d\u6d41\u884c\uff09\u3002<\/p>\n<p>$$<br \/>\nG=\\frac{1}{n-1}\\sum_{j=1}^n(2j-n-1)p(i_j)<br \/>\n$$<br \/>\n\u5176\u4e2d$i_j$\u662f\u6309\u7167\u7269\u54c1\u6d41\u884c\u5ea6$p$\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u7684\u7269\u54c1\u5217\u8868\u4e2d\u7684\u7b2c$j$\u4e2a\u7269\u54c1\u3002<\/p>\n<pre><code class=\"language-python\">def gini_index(p):\n    &quot;&quot;&quot;\u8ba1\u7b97\u57fa\u5c3c\u7cfb\u6570&quot;&quot;&quot;\n    j = 1\n    n = len(p)\n    G = 0\n\n    for item, weight in sorted(p.items(), key=itemgetter(1)):\n        G += (2*j-n-1)*weight\n\n    return G \/ float(n-1)<\/code><\/pre>\n<h1>\u591a\u6837\u6027<\/h1>\n<p>&emsp;&emsp;\u591a\u6837\u6027\u63cf\u8ff0\u4e86\u63a8\u8350\u5217\u8868\u4e2d\u7269\u54c1\u4e24\u4e24\u4e4b\u95f4\u7684\u4e0d\u76f8\u4f3c\u6027\u3002<\/p>\n<p>$$<br \/>\n\\text{Diversity}(R(u))=1-\\frac{\\sum_{i,j\\in{R(u)},i\\neq{j}}s(i,j)}{\\frac{1}{2}|R(u)|(|R(u)|-1)}<br \/>\n$$<br \/>\n\u5176\u4e2d$R(u)$\u4e3a\u7528\u6237$u$\u7684\u63a8\u8350\u5217\u8868\uff0c$s(i,j)\\in[0,1]$\u5b9a\u4e49\u4e86\u7269\u54c1$i$\u548c\u7269\u54c1$j$\u4e4b\u95f4\u7684\u76f8\u4f3c\u5ea6\u3002<\/p>\n<p>\u63a8\u8350\u7cfb\u7edf\u7684\u6574\u4f53\u591a\u6837\u6027\u5b9a\u4e49\u4e3a\uff1a<br \/>\n$$<br \/>\n\\text{Diversity}=\\frac{1}{|U|}\\sum_{u\\in{U}}\\text{Diversity}(R(u))<br \/>\n$$<\/p>\n<h1>\u83b7\u53d6\u5404\u79cd\u8bc4\u6d4b\u6307\u6807\u7684\u9014\u5f84<\/h1>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">&#8211;<\/th>\n<th style=\"text-align: center;\">\u79bb\u7ebf\u5b9e\u9a8c<\/th>\n<th style=\"text-align: center;\">\u95ee\u5377\u8c03\u5dee<\/th>\n<th style=\"text-align: center;\">\u5728\u7ebf\u5b9e\u9a8c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">\u7528\u6237\u6ee1\u610f\u5ea6<\/td>\n<td style=\"text-align: center;\">x<\/td>\n<td style=\"text-align: center;\">y<\/td>\n<td style=\"text-align: center;\">o<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u9884\u6d4b\u51c6\u786e\u5ea6<\/td>\n<td style=\"text-align: center;\">y<\/td>\n<td style=\"text-align: center;\">y<\/td>\n<td style=\"text-align: center;\">x<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u8986\u76d6\u7387<\/td>\n<td style=\"text-align: center;\">y<\/td>\n<td style=\"text-align: center;\">y<\/td>\n<td style=\"text-align: center;\">y<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u591a\u6837\u6027<\/td>\n<td style=\"text-align: center;\">o<\/td>\n<td style=\"text-align: center;\">y<\/td>\n<td style=\"text-align: center;\">o<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u65b0\u9896\u6027<\/td>\n<td style=\"text-align: center;\">o<\/td>\n<td style=\"text-align: center;\">y<\/td>\n<td style=\"text-align: center;\">o<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u60ca\u559c\u5ea6<\/td>\n<td style=\"text-align: center;\">x<\/td>\n<td style=\"text-align: center;\">y<\/td>\n<td style=\"text-align: center;\">x<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>\u957f\u5c3e\u5206\u5e03<\/h1>\n<p>$$<br \/>\nf_i(k)=\\alpha_ik^{\\beta_i} \\<br \/>\nf_u(k)=\\alpha_uk^{\\beta_u}<br \/>\n$$<br \/>\n\u5176\u4e2d$f_u(k)$\u8868\u793a\u5bf9$k$\u4e2a\u7269\u54c1\u4ea7\u751f\u884c\u4e3a\u7684\u7528\u6237\u6570\uff1b$f_i(k)$\u8868\u793a\u88ab$k$\u4e2a\u7528\u6237\u4ea7\u751f\u8fc7\u884c\u4e3a\u7684\u7269\u54c1\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a8\u8350\u7cfb\u7edf\u5e38\u7528\u8bc4\u4f30\u6307\u6807 RMSE &emsp;&emsp;\u52a0\u5927\u4e86\u5bf9\u9884\u6d4b\u4e0d\u51c6\u7684\u7528\u6237\u7269\u54c1\u8bc4\u5206\u7684\u60e9\u7f5a\u3002 $$ \\tex [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[300],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/3242"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3242"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/3242\/revisions"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}