zoukankan      html  css  js  c++  java
  • SciKit-Learn 数据集基本信息

    保留版权所有,转帖注明出处


    章节


    前面章节中,我们加载了SciKit-Learn自带的数据集digits,可以通过以下语句查看数据集中包含哪些主要内容:

    digits.keys()
    

    输出

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

    查看数据集的描述:

    print(digits.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 '@' boun.edu.tr)
        :Date: July; 1998
    
    This is a copy of the test set of the UCI ML hand-written digits datasets
    https://archive.ics.uci.edu/ml/datasets/Optical+Recognition+of+Handwritten+Digits
    
    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
    distortions.
    
    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,
    1994.
    
    .. 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.
        2005.
      - Claudio Gentile. A New Approximate Maximal Margin Classification
        Algorithm. NIPS. 2000.
    

    这是一个手写数字的数据集。

    类似地,你也可以查看其它内容:

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

    注意:如果使用read_csv()导入数据集,数据集已经分割好,导入的数据集中可能没有描述字段,但是你可以使用head()tail()来检查数据。在这种情况下,最好仔细查看数据描述文件夹!

    接下来,我们进一步了解数据集中的数据。

    可以看到,数据集中的数据都是numpy数组的格式,可以查看这些数组的数据类型,形状,长度等信息。

    import numpy as np
    
    # 打印data数组的形状
    print(digits.data.shape) # 输出:(1797, 64)
    # 打印data数组的类型
    print(digits.data.dtype) # 输出:float64
    
    # 打印target数组的形状
    print(digits.target.shape) # 输出:(1797,)
    # 打印target数组的类型
    print(digits.target.dtype) # 输出:int32
    # 打印target数组中包含的唯一值数量
    print(len(np.unique(digits.target))) # 输出: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.data中,有1797个样本,每个样本有64个特征值(实际上是像素灰度值)。

    digits.target中,包含了上面样本数据对应的目标值(样本标签),同样有1797个目标值,但10个唯一值,即0-9。换句话说,所有1797个目标值都由0到9之间的数字组成,这意味着模型要识别的是从0到9的数字。

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

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

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

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

  • 相关阅读:
    Run
    axios+Qs请求数据转表单格式
    Vue开发电子书app
    vue2.5开发去哪儿了流程
    ES6重度学习 demo实例
    JS 数组, 对象的增查改删(多语法对比)
    格式化时间戳的n种方法
    Vue中你忽略的点
    vscode代码格式化
    分隔符
  • 原文地址:https://www.cnblogs.com/jinbuqi/p/11435885.html
Copyright © 2011-2022 走看看