From bd5ac9e657d0714df2ebe8aad9ef925e16cc9e5e Mon Sep 17 00:00:00 2001 From: Khoerul Umam Date: Wed, 23 Oct 2019 05:54:27 +0700 Subject: [PATCH] change var position to improve user experience --- example.php | 18 +++++++++--------- src/Knn.php | 11 ++--------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/example.php b/example.php index 167ad7f..990ac39 100644 --- a/example.php +++ b/example.php @@ -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()); \ No newline at end of file +// print_r($data->getSample()); +// echo "\n"; +// print_r($data->getLabel()); +// echo "\n"; +// print_r($data->getPrediction()); +// echo "\n"; +// print_r($data->getSquare()); diff --git a/src/Knn.php b/src/Knn.php index 394aa60..a0567c0 100644 --- a/src/Knn.php +++ b/src/Knn.php @@ -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; @@ -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 @@ -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) @@ -116,7 +114,6 @@ public function getSample() { return $this->sample; - } //Get label raw @@ -124,7 +121,6 @@ public function getLabel() { return $this->label; - } //Get Predict raw @@ -132,7 +128,6 @@ public function getPrediction() { return $this->predictData; - } //Get result from square root from (x1-x2)^2 + (y1-y2)^2 + etc @@ -140,7 +135,5 @@ public function getSquare() { return $this->resultSquare; - } - -} \ No newline at end of file +}