Sklearn 数据集基本信息




dict_keys(['data', 'target', 'target_names', 'images', 'DESCR'])
  • data 样本数据
  • target 目标值
  • target_names 目标名称
  • images 图像格式(二维)的样本数据
  • DESCR 描述信息




.. _digits_dataset:

Optical recognition of handwritten digits dataset

**Data Set Characteristics:**

    :Number of Instances: 5620
    :Number of Attributes: 64
    :Attribute Information: 8x8 image of integer pixels in the range 0..16.
    :Missing Attribute Values: None
    :Creator: E. Alpaydin (alpaydin '@'
    :Date: July; 1998

This is a copy of the test set of the UCI ML hand-written digits datasets

The data set contains images of hand-written digits: 10 classes where
each class refers to a digit.

Preprocessing programs made available by NIST were used to extract
normalized bitmaps of handwritten digits from a preprinted form. From a
total of 43 people, 30 contributed to the training set and different 13
to the test set. 32x32 bitmaps are divided into nonoverlapping blocks of
4x4 and the number of on pixels are counted in each block. This generates
an input matrix of 8x8 where each element is an integer in the range
0..16. This reduces dimensionality and gives invariance to small

For info on NIST preprocessing routines, see M. D. Garris, J. L. Blue, G.
T. Candela, D. L. Dimmick, J. Geist, P. J. Grother, S. A. Janet, and C.
L. Wilson, NIST Form-Based Handprint Recognition System, NISTIR 5469,

.. topic:: References

  - C. Kaynak (1995) Methods of Combining Multiple Classifiers and Their
    Applications to Handwritten Digit Recognition, MSc Thesis, Institute of
    Graduate Studies in Science and Engineering, Bogazici University.
  - E. Alpaydin, C. Kaynak (1998) Cascading Classifiers, Kybernetika.
  - Ken Tang and Ponnuthurai N. Suganthan and Xi Yao and A. Kai Qin.
    Linear dimensionalityreduction using relevance weighted LDA. School of
    Electrical and Electronic Engineering Nanyang Technological University.
  - Claudio Gentile. A New Approximate Maximal Margin Classification
    Algorithm. NIPS. 2000.



# 打印数据内容 print( # 打印目标值 print( # 打印目标名称(标签) print(digits.target_names) ...




import numpy as np

# 打印data数组的形状
print( # 输出:(1797, 64)
# 打印data数组的类型
print( # 输出:float64

# 打印target数组的形状
print( # 输出:(1797,)
# 打印target数组的类型
print( # 输出:int32
# 打印target数组中包含的唯一值数量
print(len(np.unique( # 输出:10

# 打印target_names数组的形状
print(digits.target_names.shape) # 输出:(10,)
# 打印target_names数组的类型
print(digits.target_names.dtype) # 输出:int32

# 打印images数组的形状
print(digits.images.shape) # 输出:(1797, 8, 8)
# 打印images数组的类型
print(digits.images.dtype) # 输出:float64



digits.target_names包含了样本标签的名称: 0~9。

最后,可以看到digits.images数组包含3个维度: 有1797个实例,大小为8×8像素。digits.images数据与digits.data内容应该相同,只是格式不同。可以通过以下方式验证两者内容是否相同:

print(np.all(digits.images.reshape((1797, 64)) == # 输出:true

digits.images改变形状为(1797, 64),与digits.data比较,两者相等。numpy方法all()可以检测所有数组元素的值是否为True。

浙ICP备17015664号-1 浙公网安备 33011002012336号 联系我们 网站地图  
@2019 版权所有,禁止转载