Skip to Content
Python机器学习手册:从数据预处理到深度学习
book

Python机器学习手册:从数据预处理到深度学习

by Chris Albon
July 2019
Intermediate to advanced
365 pages
8h 13m
Chinese
Publishing House of Electronics Industry
Content preview from Python机器学习手册:从数据预处理到深度学习
4.9
 使用聚类的方式将观察值分组
77
[0],
[0],
[2],
[3]])
讨论
如果有足够的理由认为某个数值型特征应该被视为一个分类特征(
categorical feature
),
那么离散化会是一个卓有成效的策略。例如,
19
岁和
20
岁的人消费习惯差距很小,但
20
岁和
21
岁(在美国,
21
岁的年轻人就可以饮酒了)的人之间消费习惯差距会很大。
在这个例子中,将人群划分成能喝酒的和不能喝酒的会很有用。同样,在其他情况下,
将数据离散化为
3
个或更多区间也很有用。
在上述解决方案中,我们可以看到两种离散化方法 :针对
2
个区间使用了
scikit-learn
Binarizer
,针对
3
个及以上的区间使用了
NumPy
digitize
其实,只指定一个阈值,
digitize
也能像
Binarizer
一样二值化特征
#
将特征离散化
np.digitize(age, bins=[18])
array([[0],
[0],
[1],
[1],
[1]])
延伸阅读
y
digitize
的文档(
http://bit.ly/2HSciFP
4.9
 使用聚类的方式将观察值分组
问题描述
对观察值进行聚类操作,使相似的观察值被分为一组。
解决方案
如果你有
k
个分组,可以使用
K-Means
K
均值)聚类法将相似的观察值分到一个组,
并输出一个新的特征,以标识观察值属于哪一组
78
4
处理数值型数据
#
加载库
import pandas as pd
from sklearn.datasets ...
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

精通特征工程

精通特征工程

Alice Zheng, Amanda Casari
精通機器學習

精通機器學習

Aurélien Géron
Python数据分析基础

Python数据分析基础

Clinton W. Brownley

Publisher Resources

ISBN: 9787121369629