2016-04-08 22:36:48 +00:00
|
|
|
# ArrayDataset
|
|
|
|
|
|
|
|
Helper class that holds data as PHP `array` type. Implements the `Dataset` interface which is used heavily in other classes.
|
|
|
|
|
2019-11-02 10:41:34 +00:00
|
|
|
### Constructor Parameters
|
2016-04-08 22:36:48 +00:00
|
|
|
|
|
|
|
* $samples - (array) of samples
|
|
|
|
* $labels - (array) of labels
|
|
|
|
|
|
|
|
```
|
2018-03-03 15:04:21 +00:00
|
|
|
use Phpml\Dataset\ArrayDataset;
|
|
|
|
|
2016-04-08 22:36:48 +00:00
|
|
|
$dataset = new ArrayDataset([[1, 1], [2, 1], [3, 2], [4, 1]], ['a', 'a', 'b', 'b']);
|
|
|
|
```
|
|
|
|
|
|
|
|
### Samples and labels
|
|
|
|
|
2019-11-02 10:41:34 +00:00
|
|
|
To get samples or labels, you can use getters:
|
2016-04-08 22:36:48 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
$dataset->getSamples();
|
2016-11-03 13:03:49 +00:00
|
|
|
$dataset->getTargets();
|
2016-04-08 22:36:48 +00:00
|
|
|
```
|
2018-03-03 15:04:21 +00:00
|
|
|
|
|
|
|
### Remove columns
|
|
|
|
|
2019-11-02 10:41:34 +00:00
|
|
|
You can remove columns by their index numbers, for example:
|
2018-03-03 15:04:21 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
use Phpml\Dataset\ArrayDataset;
|
|
|
|
|
|
|
|
$dataset = new ArrayDataset(
|
|
|
|
[[1,2,3,4], [2,3,4,5], [3,4,5,6], [4,5,6,7]],
|
|
|
|
['a', 'a', 'b', 'b']
|
|
|
|
);
|
|
|
|
|
|
|
|
$dataset->removeColumns([0,2]);
|
|
|
|
|
|
|
|
// now from each sample column 0 and 2 are removed
|
|
|
|
// [[2,4], [3,5], [4,6], [5,7]]
|
|
|
|
```
|