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



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

最新文章

  1. Dev Winform 简洁界面模板制作
  2. BZOJ1798: [Ahoi2009]Seq 维护序列seq[线段树]
  3. cURL函数
  4. android 常见分辨率(mdpi、hdpi 、xhdpi、xxhdpi )及屏幕适配注意事项
  5. iOS开发UI篇—ios应用数据存储方式(偏好设置)
  6. mongoDB 修改器()
  7. [C#]Linq To Xml 介绍- 转
  8. warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
  9. 【转】winform带参数启动另一个exe
  10. java(17) - 增强for循环、装箱拆箱、可变参数
  11. jQuery Mobile 自定义按钮图标
  12. poj1797 Heavy Transportation Dijkstra算法的简单应用
  13. 通过smtp直接发送邮件
  14. Mac软件安装提示程序已损坏解决方案
  15. shell中关于file的判断(转载)
  16. 使用CodeSmith 生成代码
  17. DSO windowed optimization 代码 (3)
  18. python 美化打印json数据
  19. PAT甲题题解-1042. Shuffling Machine (20)-模拟
  20. git<commit和分支>

热门文章

  1. 二 Mybatis架构&MybatisDao的两种开发方式(原始Dao,接口动态代理)
  2. ROS学习笔记4-创建一个ROS包
  3. video-editing
  4. Spring事务原理分析-部分二
  5. Cookie存储在哪里
  6. JDBC--批量处理
  7. 「POI2017」Flappy Bird
  8. 防止SQL注入的登录页面
  9. DotNet中的继承,剖析面向对象中继承的意义
  10. gpg加密和解密