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 精通特征工程
100
7
均匀分布是
k
-
均值算法的最坏情况。如果数据密度是不均匀的,那么就可以使用较少的簇
表示更多数据。通常,很难说数据在高维空间中是如何分布的。有人很保守,会选择一个
更大的
k
,但
k
也不能过大,因为
k
会成为后续建模阶段的特征数量。
7.3
 用于分类问题的
k
-
均值特征化
当使用
k
-
均值作为特征化技术时,一个数据点可以通过它在簇中的隶属关系进行表示(簇
隶属关系分类变量的稀疏
one-hot
编码,参见
5.1.1
节),这将在下面进行说明。
如果还有目标变量,那么也可以将目标变量中的信息作为聚类过程的提示。加入目标变量
信息的一种方法是,直接将目标变量作为
k
-
均值算法的一个额外输入特征。因为我们的目
标是将所有输入维度上的欧氏距离的总和最小化,所以聚类过程除了在初始特征空间中以
外,也会在目标变量值之间平衡相似度。可以对目标变量进行缩放,来增加或减少聚类算
法对它的关注程度。目标变量之间的差距较大时,会生成更加注重分类边界的簇。
k
-
均值特征化
聚类算法可以分析数据的空间分布,因此,
k
-
均值特征化可以生成数据的压
缩空间索引,供下一阶段的模型使用。这就是
模型堆叠
的一个例子。
7-3
展示了一个简单的
k
-
均值特征生成器,它定义了一个类对象,可以拟合训练数据并
转换新数据。
7-3
 
k
-
均值特征生成器
>>> import numpy as np
>>> from sklearn.cluster import KMeans
>>> class KMeansFeaturizer:
... """Transforms ...
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

精通機器學習

精通機器學習

Aurélien Géron

Publisher Resources

ISBN: 9787115509680