以mnist数据集为例,学习逻辑回归分类模型。
这是一个十分类模型,利用softmax进行多分类。
导入相关包
import numpy as np
import tensorflow as tf
# tensorflow数据集
from tensorflow.examples.tutorials.mnist import input_data
导入mnist数据
print('Download and Extract MNIST dataset')
mnist = input_data.read_data_sets('data/', one_hot=True)
trainimg = mnist.train.images
trainlabel = mnist.train.labels
testimg = mnist.test.images
testlabel = mnist.test.labels
print('MNIST loaded')
【输出结果】
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
MNIST loaded
查看mnist数据集
print('type of "trainimg" is %s' % (type(trainimg)))
print('type of "trainlabel" is %s' % (type(trainlabel)))
print('type of "testimg" is %s