Online-Academy
Look, Read, Understand, Apply

Data Mining And Data Warehousing

Clustering_Code

id = $id;
        $this->x = $x;
        $this->y = $y;
    }
    function getId(){
        return $this->id;
    }
    function getX(){
        return $this->x;
    }
    function getY(){
        return $this->y;
    }
}

$pp = array();
    $host = "localhost";
$user = "root";
$password = "";
$db = "test";
$i = 0;
$con = mysqli_connect($host,$user,$password,$db);
$sql = "select SN, income,expenses from clustering_data";
    $res = mysqli_query($con,$sql) or die("error");
    while($r = mysqli_fetch_assoc($res)){  
      $pp[$i] = new points($r["SN"],$r["income"],$r["expenses"]);
      $i++;
    }
$p1 = $pp[4];
$dist = array();
for($i=0;$i<count($pp);$i++){
    $dist[$i] = round(sqrt(pow(($p1->getX()-$pp[$i]->getX()),2)+pow(($p1->getY()-$pp[$i]->getY()),2)),2); // euclidean distance
}

echo "
Distance from 4th point:
"; echo ""; for($i = 0;$i";} echo "
$i: ".$dist[$i]."
";