Skip to Content
Data Science from Scratch中文版|用Python學資料科學
book

Data Science from Scratch中文版|用Python學資料科學

by Joel Grus
October 2016
Beginner to intermediate
328 pages
6h 58m
Chinese
GoTop Information, Inc.
Content preview from Data Science from Scratch中文版|用Python學資料科學
模型
171
第十四章
簡單線性迴歸
藝術就像道德,總要在某個地方畫條線。
——吉爾伯特 · 基思 · 卻斯特頓(G. K. Chesterton
在第 5 章,我們曾使用
correlation
相關函式來衡量兩個變數之間線性關係的強度。但
對於大部分應用來說,只知道存在線性關係還是不夠的。我們希望能進一步了解這種
關係所蘊含的一些意義。這就是簡單線性迴歸可派上用場之處。
模型
還記得嗎?我們一直在研究 DataSciencester「使用者的朋友數量」與「使用者每天在
網站上所花費時間」兩者之間的關係。假設你總算同意,使用者是
因為
朋友越來越多,
才使他們花越來越多的時間在網站上,而不是反過來的因果關係。
社群參與部門的副總希望你建立一個模型,來描述這樣的關係。由於你已經找到一個
相當強的線性關係,因此採用線性模型是很自然的一個選擇。
具體來說,你假設有 2 個常數
α
alpha)和
β
beta),能形成以下的關係:
y
i
=
β
x
i
+
α
+
ε
i
其中
y
i
是使用者
i
每天花在網站上的分鐘數,
x
i
則是使用者
i
的朋友數量,而
ε
i
是誤差
項,它代表的是這個簡單模型未能涵蓋到的其他因素(所以當然越小越好)。
假設我們可以找到這樣一組
alpha
值和
beta
值,我們就可以用以下的方式,進行簡單
的預測:
def predict(alpha, beta, x_i):
return beta * x_i + alpha
172
第十四章:簡單線性迴歸
但我們究竟該如何挑選
alpha
beta
的值呢?我們隨意選擇任何
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

網頁應用程式設計--使用 Node 和 Express

網頁應用程式設計--使用 Node 和 Express

Ethan Brown

Publisher Resources

ISBN: 9789864761982