mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-25 06:17:34 +00:00
update classifier docs
This commit is contained in:
parent
5170c10773
commit
d2e0ce446c
@ -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
|
||||
|
27
docs/machine-learning/classification/naivebayes.md
Normal file
27
docs/machine-learning/classification/naivebayes.md
Normal 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']
|
||||
```
|
@ -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:
|
||||
|
@ -33,5 +33,4 @@ class NaiveBayes implements Classifier
|
||||
|
||||
return key($predictions);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user