版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
1.导入相关模块
import numpy as np from sklearn.datasets import fetch_openml
2.MNIST Dataset
mnist = fetch_openml("mnist_784") X = mnist.data / 255.0 y = mnist.target X.shape, y.shape
数据转换为Pandas数据框架
import pandas as pd feat_cols = ['pixel' + str(i) for i in range(X.shape[1])] df = pd.DataFrame(X, columns=feat_cols) df['label'] = y df['label'] = df['label'].apply(lambda i: str(i)) X, y = None, None print('Size of the dataframe: {}'.format(df.shape))