Last active
December 19, 2015 16:28
-
-
Save Ryokuchaneko/5983697 to your computer and use it in GitHub Desktop.
評価者に重み付けを行い(自身とどの程度好みが似ているか)
その重みづけスコアと書く評価者の評価点を掛けあわせて映画のタイトルごとにスコアを算出する
もっともスコアの高い映画が、対象とするユーザーにオススメの映画となる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getRecommendations($array, $person, $type) { | |
$totals = array(); | |
$simSums = array(); | |
$rankings = array(); | |
foreach ($array as $other => $v) { | |
if ($other == $person ){ | |
continue; | |
} elseif($type == 'pearson') { | |
$simulate = sim_pearson($array[$person], $array[$other]); | |
if($simulate <= 0) { | |
continue; | |
} else { | |
$sim = $simulate; | |
} | |
} elseif($type == 'distance'){ | |
$simulate = sim_distance($array[$person], $array[$other]); | |
if($simulate <= 0) { | |
continue; | |
} else { | |
$sim = $simulate; | |
} | |
} else { | |
echo '正しい評価方法を指定してください'; | |
exit; | |
} | |
foreach ($array[$other] as $item => $value) { | |
if(!isset($totals[$item])) { | |
$totals[$item] = 0; | |
} | |
if(!isset($simSums[$item])) { | |
$simSums[$item] = 0; | |
} | |
if (!array_key_exists($item, $array[$person]) || $array[$person][$item] == 0) { | |
$totals[$item] += $array[$other][$item]*$sim; | |
$simSums[$item] += $sim; | |
} | |
} | |
} | |
foreach ($totals as $item => $total) { | |
if($simSums[$item] != 0) { | |
$rankings[$item] = $total /$simSums[$item]; | |
} | |
} | |
arsort($rankings); | |
return $rankings; | |
} | |
$result = getRecommendations($critics, 'Toby', 'pearson'); | |
var_dump($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment