数据集获取python代码
时间: 2023-10-18 09:12:26 浏览: 82
python一键生成验证码数据集
5星 · 资源好评率100%
获取数据集的方式因数据集而异,以下是一些获取数据集的示例代码:
1. 获取MNIST数据集
```python
from tensorflow.keras.datasets import mnist
# load the MNIST dataset
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
```
2. 获取CIFAR-10数据集
```python
import tensorflow as tf
from tensorflow.keras.datasets import cifar10
# load the CIFAR-10 dataset
(train_images, train_labels), (test_images, test_labels) = cifar10.load_data()
```
3. 获取IMDB电影评论数据集
```python
from tensorflow.keras.datasets import imdb
# load the IMDB dataset
(train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
```
4. 获取Fashion-MNIST数据集
```python
import tensorflow as tf
from tensorflow.keras.datasets import fashion_mnist
# load the Fashion-MNIST dataset
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
```
这些代码示例使用了TensorFlow和Keras库中的数据集加载函数,你可以根据需要修改代码以获取你所需的数据集。
阅读全文