Pybrain has its own dataset format, which contains data and tags, and the pybrain. Dataset package is designed to contain various data formats, which is the dataset format for supervised learning

>>> from pybrain.datasets import SupervisedDataSet
>>> ds = SupervisedDataSet(2, 1)
Copy the code

The size needs to be specified during initialization, with 2 indicating that the input data is 2-dimensional and 1 indicating that the label is 1-dimensional.

The addSample method allows you to add data to a dataset

>>> ds.addSample((0, 0), (0,)) >>> ds.addSample((0, 1), (1,)) >>> ds.addSample((1, 0), (1,)) >>> ds.addSample((1, 1), (0))Copy the code

The first parameter is the data, and the second parameter is the corresponding label

>>> len(ds)
4
Copy the code
>>> for inpt, target in ds: ... print inpt, target ... [0. 0.] [0] [0. 1.] [1] [1. 0.] [1] [1. 1.] [0.]Copy the code
>>> ds['input']
array([[ 0.,  0.],
       [ 0.,  1.],
       [ 1.,  0.],
       [ 1.,  1.]])
>>> ds['target']
array([[ 0.],
       [ 1.],
       [ 1.],
       [ 0.]])
Copy the code

You can clear all data by using the clear method

>>> ds.clear()
>>> ds['input']
array([], shape=(0, 2), dtype=float64)
>>> ds['target']
array([], shape=(0, 1), dtype=float64)
Copy the code

\