Skip to content

Commit

Permalink
change var position to improve user experience
Browse files Browse the repository at this point in the history
  • Loading branch information
khumam committed Oct 22, 2019
1 parent a16225f commit bd5ac9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
18 changes: 9 additions & 9 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
$datasample = [[7, 5, 6], [3, 4, 3], [5, 7, 7], [10, 6, 1], [12, 9, 8], [11, 1, 2]]; //Sample Data
$datalabel = ['a', 'a', 'a', 'b', 'b', 'c']; //Label Data. [7,5,6] labeled by a, [10,6,1] labeled by b, etc
$key = 3; //optional. Default is 3
$predict = [13, 41]; //Input
$predict = [1, 3, 6]; //Input

$data = new Knn($datasample, $predict, $datalabel, $key);
$data = new Knn($datasample, $datalabel, $predict, $key);
echo $data->result;
echo "\n";
print_r($data->getSample());
echo "\n";
print_r($data->getLabel());
echo "\n";
print_r($data->getPrediction());
echo "\n";
print_r($data->getSquare());
// print_r($data->getSample());
// echo "\n";
// print_r($data->getLabel());
// echo "\n";
// print_r($data->getPrediction());
// echo "\n";
// print_r($data->getSquare());
11 changes: 2 additions & 9 deletions src/Knn.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Knn
protected $label; //Label Variabel


public function __construct($sample, $predictData, $dataLabel, $k)
public function __construct($sample, $dataLabel, $predictData, $k)
{

$this->sample = $sample;
Expand All @@ -34,7 +34,6 @@ public function __construct($sample, $predictData, $dataLabel, $k)

//Send the Result
$this->result = $this->label($dataLabel, $k);

}

//Function to count (x1 - x2)^2 , (y1-y2)^2 , etc
Expand Down Expand Up @@ -93,7 +92,6 @@ public function label($dataLabel, $k)

$sendToArrayOrder = $this->arrayOrder($orderByK);
return $sendToArrayOrder;

}

//Function to searching match label. Counting the highest label that have lower values (shorter distance)
Expand All @@ -116,31 +114,26 @@ public function getSample()
{

return $this->sample;

}

//Get label raw
public function getLabel()
{

return $this->label;

}

//Get Predict raw
public function getPrediction()
{

return $this->predictData;

}

//Get result from square root from (x1-x2)^2 + (y1-y2)^2 + etc
public function getSquare()
{

return $this->resultSquare;

}

}
}

0 comments on commit bd5ac9e

Please sign in to comment.