mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-22 04:55:10 +00:00
Apply cs fixes for NaiveBayes
This commit is contained in:
parent
e603d60841
commit
d19ddb8507
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user