 |
|
กำลังทำระบบแนะนำภาพยนตร์ครับ
แล้วต้องการหาค่าความคล้ายคลึงของ user โดยใช้ euclidean distance algorithm ครับ โดยที่ได้เก็บข้อมูลการให้คะแนนของ user ไว้
โครงสร้างของตารางใน database เป็นแบบนี้ครับ

อยากให้ช่วนแนะนำว่า จะเอาข้อมูลจากในตารางนี้มาเข้าสูตรได้อย่างไร ตอนนี้มีโค้ดที่ไว้คำนวนค่านี้อยู่แล้วครับ
Code (PHP)
function subtract_and_square($n, $m)
{
return(pow($n - $m, 2));
}
function find_distance_between($p, $q)
{
$numargs = func_num_args();
if ($numargs != 2)
{
die("You must supply 2, and only 2, coordinates, no more, no less.\n");
}
else if (sizeof($p) != sizeof($q))
{
die("Coordinates do not have the same number of elements.\n");
}
else
{
$c = array_map("subtract_and_square", $p, $q);
return pow(array_sum($c), .5);
}
}
//test
$arr1 = array(4,3);
$arr2 = array(2,2);
echo find_distance_between($arr1,$arr2);
ตอนนี้ติดปัญหาอยู่ที่ว่า นึกภาพไม่ออกว่าจะเอาข้อมุลที่อยู่ในตารางตามรุปที่แนบดึงค่ามาคำนวนในสูตรได้อย่างไรครับ ใครมีแนวทาง
พอจะชี้แนะได้ไหมครับ ขอบคุณมากครับ
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2012-03-11 15:50:08 |
By :
tongdee |
View :
1404 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |