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



前面章节中,我们加载了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。

SciKit-Learn 数据集基本信息的更多相关文章

  1. scikit learn 模块 调参 pipeline+girdsearch 数据举例:文档分类 (python代码)

    scikit learn 模块 调参 pipeline+girdsearch 数据举例:文档分类数据集 fetch_20newsgroups #-*- coding: UTF-8 -*- import ...

  2. Scikit Learn: 在python中机器学习

    转自:http://my.oschina.net/u/175377/blog/84420#OSC_h2_23 Scikit Learn: 在python中机器学习 Warning 警告:有些没能理解的 ...

  3. (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探

    一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...

  4. (原创)(四)机器学习笔记之Scikit Learn的Logistic回归初探

    目录 5.3 使用LogisticRegressionCV进行正则化的 Logistic Regression 参数调优 一.Scikit Learn中有关logistics回归函数的介绍 1. 交叉 ...

  5. Scikit Learn

    Scikit Learn Scikit-Learn简称sklearn,基于 Python 语言的,简单高效的数据挖掘和数据分析工具,建立在 NumPy,SciPy 和 matplotlib 上.

  6. Query意图分析:记一次完整的机器学习过程(scikit learn library学习笔记)

    所谓学习问题,是指观察由n个样本组成的集合,并根据这些数据来预测未知数据的性质. 学习任务(一个二分类问题): 区分一个普通的互联网检索Query是否具有某个垂直领域的意图.假设现在有一个O2O领域的 ...

  7. 机器学习-scikit learn学习笔记

    scikit-learn官网:http://scikit-learn.org/stable/ 通常情况下,一个学习问题会包含一组学习样本数据,计算机通过对样本数据的学习,尝试对未知数据进行预测. 学习 ...

  8. Linear Regression with Scikit Learn

    Before you read  This is a demo or practice about how to use Simple-Linear-Regression in scikit-lear ...

  9. 如何使用scikit—learn处理文本数据

    答案在这里:http://www.tuicool.com/articles/U3uiiu http://scikit-learn.org/stable/modules/feature_extracti ...

随机推荐

  1. B树 VS B+树

    参考:https://www.cnblogs.com/vincently/p/4526560.html

  2. CTU Open Contest 2019 AB题

    小菜鸡飘过 A: Beer Barrels 题意:给出四个整数:A,B,K,C,:A,B,C都是大于0的个位数,问在所有仅有A或者B组成的K位数中,数字C的个数是多少 思路: 1.先考虑特殊情况: ( ...

  3. Linux--add the PPA to your system

    Add a PPA to your system with a single line in your terminal step1:on the PPA's overview page,look f ...

  4. 修改DUILIB任务栏中显示的图标和EXE图标

    在资源中添加ICO图标,获取属性名,在主窗口文件中的函数InitWindow或OnCreate中添加如下代码: SetIcon(IDR_MAINFRAME); 修改EXE显示图标,在主窗口中加入如下代 ...

  5. 第1节 kafka消息队列:1、kafka基本介绍以及与传统消息队列的对比

    1. Kafka介绍 l  Apache Kafka是一个开源消息系统,由Scala写成.是由Apache软件基金会开发的一个开源消息系统项目. l  Kafka最初是由LinkedIn开发,并于20 ...

  6. English_Rhymes_Phonics_resource

    English_Rhymes_Phonics_resource 1. 英语启蒙早有用吗?_英语启蒙 2. 26个英文字母背后的故事_英语启蒙 3. Phonics Song 4. 学Phonics前先 ...

  7. Linux centosVMware shell脚本介绍、shell脚本结构和执行、date命令用法、shell脚本中的变量

    一. shell脚本介绍 shell是一种脚本语言 aming_linux blog.lishiming.net 可以使用逻辑判断.循环等语法 可以自定义函数 shell是系统命令的集合 shell脚 ...

  8. vim的几种模式

    Normal Mode 普通模式 功能:在这种模式下可以移动光标等. 进入:默认进入vim之后,处于这种模式.在其他模式下狂按ESC后进入此模式. Visual Mode 可视模式 功能:在这种模式下 ...

  9. 【Luogu4448】 [AHOI2018初中组]球球的排列

    题意 有 \(n\) 个球球,每个球球有一个属性值 .一个合法的排列满足不存在相邻两个球球的属性值乘积是完全平方数.求合法的排列数量对 \(10^9+7\) 取膜. \(n\le 300\) (本题数 ...

  10. ttf格式文件

    TTF(TrueTypeFont):是一种字库名称.TTF文件:是Apple公司和Microsoft公司共同推出的字体文件格式.要使用的下载的字体文件只要把它(*.ttf)放到C:\WINDOWS\F ...