
TF.Keras.Datasets数据源
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
TF.Keras.Datasets是TensorFlow框架中的一个模块,提供了多种常用的机器学习和深度学习的数据集,便于开发者快速进行模型训练与测试。
以下是关于不同数据集的描述及加载代码:
- `boston_housing` 模块:波士顿房价回归数据集。
- `cifar10` 模块:CIFAR10 小型图像分类数据集。
- `cifar100` 模块:CIFAR100 小型图像分类数据集。
- `fashion_mnist`模块:Fashion-MNIST 数据集。
- `imdb` 模块:IMDB 电影评论情感分析数据集。
- `mnist` 模块:MNIST 手写数字识别数据集。
- `reuters` 模块:路透社新闻主题分类数据集。
导入 TensorFlow 和 Keras:
```python
import tensorflow as tf
from tensorflow import keras
```
加载 Fashion-MNIST 数据集:
```python
fashion_mnist = keras.datasets.fashion_mnist
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
```
加载 MNIST 数据集:
```python
mnist = keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
```
加载 CIFAR-100 数据集:
```python
cifar100 = keras.datasets.cifar100
(x_train, y_train), (x_test, y_test) = cifar100.load_data()
```
加载 CIFAR-10 数据集:
```python
cifar10 = keras.datasets.cifar10
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
```
加载 IMDB 评论数据集并处理文本数据:
```python
imdb = keras.datasets.imdb
(x_train, y_train), (x_test, y_test) = imdb.load_data()
# 获取单词到索引的映射字典
word_index = imdb.get_word_index()
reverse_word_index = dict([(value, key) for (key, value) in word_index.items()])
decoded_review = .join([reverse_word_index.get(i - 3, ?) for i in x_train[0]])
print(decoded_review)
```
加载波士顿房价数据集:
```python
boston_housing = keras.datasets.boston_housing
(x_train, y_train), (x_test, y_test) = boston_housing.load_data()
```
加载路透社新闻主题分类数据集:
```python
reuters= keras.datasets.reuters
(x_train, y_train), (x_test, y_test) = reuters.load_data()
# 获取单词到索引的映射字典(路径为json文件)
tf.keras.datasets.reuters.get_word_index(path=reuters_word_index.json)
```
以上是这些数据集的基本加载方法。
全部评论 (0)


