update classifier docs

This commit is contained in:
Arkadiusz Kondas 2016-04-16 21:41:37 +02:00
parent 5170c10773
commit d2e0ce446c
7 changed files with 35 additions and 7 deletions

View File

@ -5,9 +5,11 @@ Classifier implementing the k-nearest neighbors algorithm.
### Constructor Parameters
* $k - number of nearest neighbors to scan (default: 3)
* $distanceMetric - Distance class, default Euclidean (see Distance Metric documentation)
```
$classifier = new KNearestNeighbors($k=4);
$classifier = new KNearestNeighbors($k=3, new Minkowski($lambda=4));
```
### Train

View File

@ -0,0 +1,27 @@
# NaiveBayes Classifier
Classifier based on applying Bayes' theorem with strong (naive) independence assumptions between the features.
### Train
To train a classifier simply provide train samples and labels (as `array`):
```
$samples = [[5, 1, 1], [1, 5, 1], [1, 1, 5]];
$labels = ['a', 'b', 'c'];
$classifier = new NaiveBayes();
$classifier->train($samples, $labels);
```
### Predict
To predict sample class use `predict` method. You can provide one sample or array of samples:
```
$classifier->predict([3, 1, 1]);
// return 'a'
$classifier->predict([[3, 1, 1], [1, 4, 1]);
// return ['a', 'b']
```

View File

@ -4,6 +4,7 @@ pages:
- Machine Learning:
- Classification:
- KNearestNeighbors: machine-learning/classification/knearestneighbors.md
- NaiveBayes: machine-learning/classification/naivebayes.md
- Cross Validation:
- RandomSplit: machine-learning/cross-validation/randomsplit.md
- Datasets:

View File

@ -33,5 +33,4 @@ class NaiveBayes implements Classifier
return key($predictions);
}
}

View File

@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);
declare (strict_types = 1);
namespace Phpml\Classifier\Traits;
@ -23,5 +24,4 @@ trait Predictable
return $predicted;
}
}

View File

@ -1,11 +1,11 @@
<?php
declare(strict_types = 1);
declare (strict_types = 1);
namespace Phpml\Classifier\Traits;
trait Trainable
{
/**
* @var array
*/
@ -25,5 +25,4 @@ trait Trainable
$this->samples = $samples;
$this->labels = $labels;
}
}

View File

@ -26,7 +26,7 @@ class CsvDataset extends ArrayDataset
throw DatasetException::missingFile(basename($filepath));
}
if(false === $handle = fopen($filepath, 'r')) {
if (false === $handle = fopen($filepath, 'r')) {
throw DatasetException::cantOpenFile(basename($filepath));
}