Skip to Content
精通特征工程
book

精通特征工程

by Alice Zheng, Amanda Casari
April 2019
Intermediate to advanced
172 pages
4h 39m
Chinese
Posts & Telecom Press
Content preview from 精通特征工程
88
6
6.3
 
PCA
实战
让我们通过在图像数据上应用
PCA
,更好地理解一下
PCA
MNIST
数据集中包含了从
0
9
这几个数字的手写体的图像,初始图像是
28
像素×
28
像素。
scikit-learn
中有个分辨
率更低的图像子集,每张图像被下采样为
8
像素×
8
像素。
scikit-learn
中的初始数据有
64
个维度。在例
6-1
中,我们要使用
PCA
,并使用前
3
个主成分对数据集进行可视化。
6-1
 
scikit-learn
数字数据集(
MNIST
数据集的一个子集)的主成分分析
>>> from sklearn import datasets
>>> from sklearn.decomposition import PCA
# 载入数据
>>> digits_data = datasets.load_digits()
>>> n = len(digits_data.images)
# 每张图像被表示为一个8×8数组。将数组扁平化,作为PCA的输入
>>> image_data = digits_data.images.reshape((n, -1))
>>> image_data.shape
(1797, 64)
# 数字的真实值标签在每张图片中
>>> labels = digits_data.target
>>> labels
array([0, 1, 2, ..., 8, 9, 8])
# 为这个数据集拟合一个PCA转换器
# 自动选择主成分的数目,使主成分能解释至少80% ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Kafka权威指南

Kafka权威指南

Neha Narkhede, Gwen Shapira, Todd Palino
精通機器學習

精通機器學習

Aurélien Géron

Publisher Resources

ISBN: 9787115509680