php-ml/docs/machine-learning/classification/naive-bayes.md

28 lines
618 B
Markdown
Raw Normal View History

2016-04-16 19:41:37 +00:00
# NaiveBayes Classifier
Classifier based on applying Bayes' theorem with strong (naive) independence assumptions between the features.
### Train
2016-05-02 11:49:19 +00:00
To train a classifier simply provide train samples and labels (as `array`). Example:
2016-04-16 19:41:37 +00:00
```
$samples = [[5, 1, 1], [1, 5, 1], [1, 1, 5]];
$labels = ['a', 'b', 'c'];
$classifier = new NaiveBayes();
$classifier->train($samples, $labels);
```
### Predict
2016-05-02 11:49:19 +00:00
To predict sample label use `predict` method. You can provide one sample or array of samples:
2016-04-16 19:41:37 +00:00
```
$classifier->predict([3, 1, 1]);
// return 'a'
$classifier->predict([[3, 1, 1], [1, 4, 1]);
// return ['a', 'b']
```