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 精通特征工程
16
2
2.3.1
 对数变换实战
我们看一下对数变换在监督式学习中有什么作用。本节会使用前面的两个数据集。对
Yelp
点评数据集,我们使用点评数量来预测一个商家的平均评分(见例
2-8
)。对于
Mashable
新闻文章数据集,我们使用文章中的单词数量来预测文章流行度。因为两个预
测的输出都是连续型数值,所以我们可以使用简单线性回归来构造模型。我们使用
scikit-
learn
,分别在进行了对数变换和未进行对数变换的特征上进行
10-
折交叉验证的线性回归。
我们使用
R
方分数来评价模型,它衡量的是训练出的回归模型预测新数据的能力。良好
的模型会有较高的
R
方分数。完美的模型能得到的最大
R
方分数是
1
R
方分数可以是负
的,一个糟糕的模型可以得到任意低的负分。通过交叉验证,我们不仅能得到分数的估计
值,还能得到它的方差,这有助于我们判断两种模型之间的差异是否是有意义的。
2-8
 
使用对数变换后的
Yelp
点评数量预测商家的平均评分
>>> import pandas as pd
>>> import numpy as np
>>> import json
>>> from sklearn import linear_model
>>> from sklearn.model_selection import cross_val_score
# 使用前面加载的Yelp点评数据框,计算Yelp点评数量的对数变换值。
# 注意,我们为原始点评数量加1,以免当点评数量为0时,对数运算结果得到负无穷大。
>>> ...
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