UCIHousing

class paddle.text. UCIHousing ( data_file=None, mode='train', download=True ) [源代码]

该类是对 UCI housing 测试数据集的实现。

参数

  • data_file (str) - 保存数据的路径,如果参数 :attr:`download`设置为 True,可设置为 None。默认为 None。

  • mode (str) - 'train' 或 'test' 模式。默认为 'train'。

  • download (bool) - 如果 :attr:`data_file`未设置,是否自动下载数据集。默认为 True。

返回值

Dataset,UCI housing 数据集实例。

代码示例

>>> import paddle
>>> from paddle.text.datasets import UCIHousing

>>> class SimpleNet(paddle.nn.Layer):
...     def __init__(self):
...         super().__init__()
...
...     def forward(self, feature, target):
...         return paddle.sum(feature), target

>>> paddle.disable_static()

>>> uci_housing = UCIHousing(mode='train')

>>> for i in range(10):
...     feature, target = uci_housing[i]
...     feature = paddle.to_tensor(feature)
...     target = paddle.to_tensor(target)
...
...     model = SimpleNet()
...     feature, target = model(feature, target)
...     print(feature.shape, target.numpy())
[] [24.]
[] [21.6]
[] [34.7]
[] [33.4]
[] [36.2]
[] [28.7]
[] [22.9]
[] [27.1]
[] [16.5]
[] [18.9]