Apply cs fixes for NaiveBayes

This commit is contained in:
Arkadiusz Kondas 2017-01-17 16:26:43 +01:00
parent e603d60841
commit d19ddb8507

View File

@ -12,24 +12,62 @@ use Phpml\Math\Statistic\StandardDeviation;
class NaiveBayes implements Classifier
{
use Trainable, Predictable;
const CONTINUOS = 1;
const NOMINAL = 2;
const EPSILON = 1e-10;
private $std = array();
private $mean= array();
private $discreteProb = array();
private $dataType = array();
private $p = array();
/**
* @var array
*/
private $std = [];
/**
* @var array
*/
private $mean= [];
/**
* @var array
*/
private $discreteProb = [];
/**
* @var array
*/
private $dataType = [];
/**
* @var array
*/
private $p = [];
/**
* @var int
*/
private $sampleCount = 0;
/**
* @var int
*/
private $featureCount = 0;
private $labels = array();
/**
* @var array
*/
private $labels = [];
/**
* @param array $samples
* @param array $targets
*/
public function train(array $samples, array $targets)
{
$this->samples = $samples;
$this->targets = $targets;
$this->sampleCount = count($samples);
$this->featureCount = count($samples[0]);
// Get distinct targets
$this->labels = $targets;
array_unique($this->labels);
foreach ($this->labels as $label) {
@ -79,6 +117,7 @@ class NaiveBayes implements Classifier
* @param array $sample
* @param int $feature
* @param string $label
* @return float
*/
private function sampleProbability($sample, $feature, $label)
{