Skip to content

Instantly share code, notes, and snippets.

@Ryokuchaneko
Ryokuchaneko / PHPで学ぶ集合知プログラミング2.4
Last active December 19, 2015 16:28
評価者に重み付けを行い(自身とどの程度好みが似ているか) その重みづけスコアと書く評価者の評価点を掛けあわせて映画のタイトルごとにスコアを算出する もっともスコアの高い映画が、対象とするユーザーにオススメの映画となる
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) {
@Ryokuchaneko
Ryokuchaneko / PHPで学ぶ集合知プログラミング2.3
Last active December 19, 2015 16:28
二人の評価者のユークリッド距離によるスコアを算出するsim_distanceとピアソン相関によるスコアを算出するsim_peasonを定義 リストの中から最も好みの似ている評価者を選び出すtopMatchesを定義
function sim_distance($person1, $person2){
$si = array();
foreach ($person1 as $k => $v) {
if (array_key_exists($k, $person2)) {
$si[$k] = 1;
}
}
if (count($si) == 0) {
return 0;
}
@Ryokuchaneko
Ryokuchaneko / phpで学ぶ集合知プログラミング2.2
Last active December 19, 2015 16:28
まずはデータ・セットの作成
$critics=array('Lisa Rose'=> array('Lady in the Water' =>2.5, 'Snakes on a Plane' =>3.5,
'Just My Luck'=> 3.0, 'Superman Returns'=> 3.5, 'You, Me and Dupree'=> 2.5,
'The Night Listener'=> 3.0),
'Gene Seymour' => array('Lady in the Water'=> 3.0, 'Snakes on a Plane'=> 3.5,
'Just My Luck'=> 1.5, 'Superman Returns'=> 5.0, 'The Night Listener'=> 3.0,
'You, Me and Dupree'=> 3.5),
'Michael Phillips'=> array('Lady in the Water'=> 2.5, 'Snakes on a Plane'=> 3.0,
'Superman Returns'=> 3.5, 'The Night Listener'=> 4.0),
'Claudia Puig'=> array('Snakes on a Plane'=> 3.5, 'Just My Luck'=> 3.0,
'The Night Listener'=> 4.5, 'Superman Returns'=> 4.0,