Professional Documents
Culture Documents
Data Analytics and Modeling With R
Data Analytics and Modeling With R
Giảng viên
• TS. Nguyễn Quang (S-LAB)
• ThS. Hoàng Hải Nguyên (S-LAB, IcareBenefits)
Website: s-lab.vn - Email: info@s-lab.vn - Tel: 0399678936 - FB: Học Machine Learning và Deep Learning
@
DATA ANALYTICS
MACHINE LEARNING
DEEP LEARNING
TỔ CHỨC BỞI: s-lab.vn – Song Cau Co. Ltd. – Một đối tác của BigML.com
Nhà phát triển platform Machine Learning hàng đầu thế giới
bigml.com
Kết luận:
Ø Doanh nghiệp không khai thác được dữ liệu sẽ lãng phí cơ hội kinh doanh
Ø Cần có các phương pháp Khoa học và Công nghệ phù hợp
4 bottlenectks:
Ø Culture
Ø Lack of data
Ø Lack of skills
Ø Business use cases
https://www.quora.com/What-is-the-difference-
between-data-analytics-and-Machine-learning
• Compliance: Basel,…
https://www.facebook.com/permalink.php?story_fbid=284787
Easy Data Science @ s-lab.vn - Nguyen Quang
1975252834&id=2743319952374704
Nhà Khoa học dữ liệu - Data Scientist
Vai trò mới và quan trọng
Nhiệm vụ:
- Nhận dạng các vấn đề kinh doanh và biến đổi thành bài toán Dữ liệu
- Thiết kế, xây dựng, triển khai các mô hình TK và KHDL trên dữ liệu lớn
- Nhận diện ra tri thức và khuyến nghị hành động kinh doanh
Data science
Kỹ năng:
“In God we trust.
- Quantitative DOMAIN
EXPERTISE
All others bring
data”.
“Ta tin Thượng đế.
- Technical STATISTICAL
RESEARCH
DATA
PROCESSING
Ngoài ra, là dữ
liệu”.
W.E. Deming
• Đặc điểm cần có của các công cụ trong thời đại dữ liệu?
https://www.kdnuggets.com/2011/08/poll-languages-for-
data-mining-analytics.html
biến
quan sát
Population Sample
Hệ số
res the •relative tương
strength quan
of the linear relationship between two
ical variables cov (X , Y) The sample covariance:
r n
e coefficient of correlation: SX SY ( Xi X)( Yi Y)
cov ( X , Y ) i 1
n n n n 1
(Xi X)(Yi Y) (Xi X)2 2
(Yi Y )
i 1
SX i 1
SY i 1
Only concerned with the strength of the relationship
n 1 n 1 n 1
No causal effect is implied
61
Thư viện ’dplyr’: dataframe %>% select(variables) %>% group_by(dimension) %>% summarise(Value1 =
fun(measure), Value2 = fun(measure))
n n
(Xi X )2 (Xi X)2
S2 i 1
S i 1
n -1 n -1
Where X = arithmetic mean
• Skew, Kurtosis n = sample size
Xi = ith value of the variable X
Standard variation
Most commonly used measure of variation
Shows variation about the mean
Is the square root of the variance
Has the same units as the original data
@ 46
Easy Data Science @ s-lab.vn - Nguyen Quang
DEA vs. Presentation
• DEA khám phá các đặc tính và mối quan hệ trong dữ liệu, là bước chuẩn bị cho mô hình
• DEA không nên được dùng cho báo cáo cuối cùng
DEA Presenta+on
• Có quá nhiều dữ liệu nhưng không thu thập được -> Phải thống nhất dữ liệu
• Nhiều dữ liệu nhưng không match với nhau được (consolidate data)
Moving/Gathering
• Dữ liệu bị lỗi quá nhiều Từ nhiều nguồn khác nhau
• Làm lại các thao tác xử lý
• Business user không được quyền truy cập Making it consistent
Quy ước khác nhau: số hiệu, giá trị
• Business user không tự thao tác được True/False vs 1/0,…
• Báo cáo không hiển thị rõ những xu hướng quan trọng Đơn vị khác nhau: inch vs cm, $ vs
• Các báo cáo không đồng nhất VND,…
• Làm sao ra các quyết định? Cleaning up
Lỗi máy đo
Lỗi nhập liệu
Thiếu dữ liệu
Ralph Kimball, Margy Ross, The Data Warehouse Toolkit, 2nd Edition, 2002
Product – Chocolate
Date – May 2003
Date
Region – South East
Region
Measure – Sales
Product
How much Chocolate did we sell in the South East in May 2003?
Count of Id
BEVERAGES BOOKS
100K 2M 9M
BOOKS BREAD
Year of Date
800K 1M BREAD/BAKERY CELEB
Stor.. 2013 2014 2015 2016 2017
CELEBRATION 1 CLEAN
80K 0M 8M
Distinct count of Id
2
3 DAIRY
FALSE NA TRUE CLEANING 4
DELI
Unit Sales
5
600K DAIRY 6
7 EGGS
60K 8
Unit Sales Histogram DELI
9
7M FROZE
EGGS 10
11 GROCE
400K 12
40K FROZEN FOODS 13 GROCE
Count of Unit Sales 14
GROCERY I 15 6M HARD
3K 16
17 HOME
GROCERY II
Unit Sales
200K 18
20K 19 HOME
2K HARDWARE 20
21 5M HOME
HOME AND KITCHEN I 22
23 HOME
0K 0K HOME AND KITCHEN II 24
1K 25 LADIE
February 2013
May 2013
August 2013
November 2013
February 2014
May 2014
August 2014
November 2014
February 2015
May 2015
August 2015
November 2015
February 2016
May 2016
August 2016
November 2016
February 2017
May 2017
26
HOME APPLIANCES 27 LAWN
28 4M
0K HOME CARE 29 LINGE
30
LADIESWEAR 31 LIQUO
1,000 10,000 32
33 MAGA
LAWN AND GARDEN 34 3M
Unit Sales (bin) 35 MEAT
LINGERIE 36
37 PERSO
LIQUOR,WINE,BEER 38
39 PET SU
Store Item Distribution MAGAZINES 40
41
2M
PLAYE
42
MEATS 43 POULT
2000K 44
PERSONAL CARE 45 PREPA
46 1M
PET SUPPLIES 47 PRODU
48
49 SCHOO
1500K PLAYERS AND ELECTR.. 50
51 SEAFO
Unit Sales
POULTRY 52 0M
53
PREPARED FOODS 54 2013 2014 2015 2016 2017
1000K PRODUCE Year of Date
SCHOOL AND OFFICE S..
500K SEAFOOD
0K
3 7 11 15 19 23 27 31 35 39 43 47 51
https://www.ien.com/advanced-manufacturing/blog/21020235/10-steps-for-building-your-bi-dashboard
BI giúp đưa ra những quyết định quan trọng, tầm ML sử dụng kiến thức máy học và công nghệ để tạo
ảnh hướng lớn, hiệu quả nhanh khi có những vấn ra giá trị, thường được tích hợp vào trong hệ thống
đề hay cơ hội tồn tại trong doanh nghiệp. vận hành, tự động đưa ứng dụng vào sản phẩm.
https://www.facebook.com/H%E1%BB%8Dc-Machine-Learning-v%C3%A0-
Deep-Learning-2743319952374704/?modal=admin_todo_tour
2. Dữ liệu bất thường (Outliers detection) -> loại bỏ (do sai) hoặc biến đổi
3. Biến đổi dữ liệu -> biến đổi cho phù hợp với mô hình
pairs() function in R
Mục đích: cải thiện mô hình, giúp mô hình chính xác hơn
1. Tạo biến mới
1. Polynomial (+ interacting term)
2. Domain knowledge features (ratios)
2. Lựa chọn (lọc) biến
1. Correlation
2. VIF
3. Biến đổi biến
1. Outliers (truncate, group)
2. Chuyển đổi thang log, sqrt
3. New dummy (Chuẩn hóa theo khu vực)
4. Cat. -> One-hot
5. PCA
6. Cont. -> cat.
• Không gian mẫu – population: là tập hợp tất cả các đối tượng quan tâm (không gian lớn)
• Mẫu – sample: là một tập hợp con được thu thập ≡ dataset
• Dữ liệu – data: là các giá trị của các biến trong mẫu
• Mô hình – model: là một mô hình (xác suất) được đề xuất cho phân bố của không giam mẫu
• Tham số - parameter: là tham số của mô hình (có thể có mô hình không tham số)
• Thống kê – statistics : là một đại lượng số đo được từ mẫu, đặc trưng cho tính chất của mẫu
σs
Sample X
μ
hKps://www.123rf.com/photo_34866087_stock-vector-stand-with-charts-graphs-
and-parameters-sta1s1c-business-concept-of-analy1cs.html Easy Data Science @ s-lab.vn - Nguyen Quang
Phân phối chuẩn
• The Standardized Normal Z ~ N(0, 1) • X ~ N(µ, s) -> Biến đổi thành Z (mean = 0
và sd = 1)
X -μ
Z=
σ
• Ví dụ:
– X theo pp chuẩn với µ = 30 và s = 2, Pnh xác
suất P(28 <= X <= 32)?
– Tính giá trị a, b, sao cho P(a <= X <= b) = 95%?
$
'& ~ N(µ, ss) với !" =
%
μx = μ
Normal Population
μ x
Distribution
Normal Sampling
Distribution
(has the same mean) x
μx
Easy Data Science @ s-lab.vn - Nguyen Quang
Ước lượng và khoảng tin cậy
• Định lý giới hạn trung tâm • Nếu biết '& và s, ta có thể ước lượng µ?:
σ
$ X ± Z α/2
'& ~ N(µ, ss) với !" = n
%
S
X ± tα / 2
n
• tα/2 là giá trị cực điểm cho xác suất α/2 của
phân phối Student với df = n-1
http://statcalculators.com/students-t-distribution-table/
p(1- p)
• Theo phân phối chuẩn với s được ước lượng bởi
n
• Khoảng tin cậy p(1 - p)
p ± Z α/2
n
• Thiết lập giả định null hypothesis (H0) và giả định thay thế bằng HA
• Nếu không bác bỏ H0, thì không đưa ra được kết luận/hành động gì
– Giữ nguyên trạng thái hiện tại, mặc dù không kết luận là nó đúng
• H0 luôn là giả thuyết về tham số của không gian mẫu, có chứa dấu “=“
"! -> T
Actual Situation
Sponsor
Người tài trợ
Business
users Easy Data Science @ s-lab.vn - Nguyen Quang
The Data Science team - Salary
Data Manager
BA Statistician Data Arch.
DB Admin
Thực tế
• Là phương pháp đơn giản nhất trong các phương pháp ML
• HQTT được sử dụng rộng rãi trong thực tế
• Nên được áp dụng trước những phương pháp ML khác
• Biến độc lập: một hoặc nhiều trong số 3 biến chi phí
cho các kênh TV, Radio, Newspaper
! = $% + $' (+ )
!+ = $% + $' (
Ước lượng hệ số bằng
q Đường dự báo phương pháp Hồi quy
NGUYEN QUANG 9
Bài toán Hồi quy tuyến tính một biến
Tối ưu tham số
q Trên đồ thị scatter:
!+ = 7.03 + 0.047(
!- $'
Xác định hệ số ),
• Nếu kinh phí TV bằng 0,
doanh số ước lượng là 7.03
!+,
$% • Nếu kinh phí TV tăng thêm
q Đường dự báo, xác định bởi 2 tham số $%, $', được ước lượng từ bộ dữ
1, doanh số ước lượng tăng
thêm 0.047 (hay 100 và 4,7)
liệu đã quan sát được
Độ chính xác của các
q Đường dự báo càng gần bộ dữ liệu càng tốt ≈ các biến số ) càng hệ nhỏ
số nàycàng
đến đâu?
tốt () nhỏ theo nghĩa độ lớn)
q Phương pháp phổ biến là bình
NGUYENphương
QUANG tối thiểu (least square): tối thiểu 14
giá trị mean-square-error (MSE), với 1 n
2
MSE = ∑ Yi − Yˆi ( )
n 2 n i=1
1
MSE = ∑ Yi − Yˆi 1 n
( ) 2
n i=1 = ∑ (Yi − β̂0 − β̂1 X1 −− β̂ p X p )
n i=1
n
1 2
Easy Data Science @ s-lab.vn - Nguyen Quang
(
= ∑ Yi − β̂0 − β̂1 X1 −− β̂ p X p
n i=1
)
Example: Advertising budget
Xác định hệ số
q Kết quả:
$.% = 56 − $.' 1̅
với 1 7
1̅ = ; 1-
: -8'
1 7
56 = ; 5-
: -8'
NGUYEN QUANG 13
Example: Advertising budget
Phép thử hệ số (t-test)
q Nếu ước lượng được t đủ lớn, xác suất $' = 0 là rất thấp Sai số của không mô hình
'
q Ước lượng bởi !6 = ∑7-8' !- = 14.02
7
Sai số TB sd(Y) = 5.21
sd(Advertising$Sales)
q p-value: Xác suất để t có giá trị ước tính được nếu $' = 0
q t và p-value là tương đương: q Với mô hình, sai số TB giảm còn 3.25
Ø t > 2 tương đương p-value < 0.05
∑n 6 m n
lof(kl gk) g∑lof p
m
Ø t > 2.33 tương đương p-value < 0.02 q Định nghĩa j * = ∑n 6 m
lof (kl gk)
Ø … = tỷ lệ phương sai giải thích bởi mô hình
q Trong ví dụ trên, cả $%, $' đều có ý nghĩa (khác 0) với độ tin cậy > 99.9% q qr thường được dùng để đánh giá hiệu quả
mô hình hồi quy tuyến tính
Easy QUANG
NGUYEN Data Science @ s-lab.vn - Nguyen Quang
NGUYEN QUANG 18
Multiple Regression
Bài toán Hồi quy tuyến tính nhiều biến
• Mở rộng cho nhiều biến
q Giả định mô hình hồi quy nhiều biến sau
q Các hệ số được ước lượng tương tự bởi “least square” – tối thiểu MSR
7 7
MSR = ; (!- − !+- )* =; (!- − $.% − $.' (-' − $.* (-* − $.s (-s)*
-8' -8'
! = pháp
$% ma +trận
$'và('không hiện+
+ $thể* (
q Kết quả được tính bằng phương
* ở$đây ( + )
s s
q Ta có thể tính được với R bằng hàm lm
(cho 3 biến)
q Các hệ số được ước lượng tương tự bởi “least square” – tối thiểu MSR
7 7
MSR = ; (!- − !+- )* =; (!- − $.% − $.' (-' − $.* (-* − $.s (-s)*
-8' -8'
NGUYEN QUANG 28
NGUYEN QUANG 27
Easy Data Science @ s-lab.vn - Nguyen Quang
Multiple Regression - Các vấn đề cần quan tâm
• Adjusted R2
• F-test
• Biến phân loại
• Tương tác biến
• Quan hệ phi tuyến
• Kiểm định hệ số
• Khoảng tin cậy của hệ số
Incom
Incom
e
e
ity
yit
or
Ye
or
Ye
ni
ar
ni
a rs so
Se
Se
of fE
Ed du
uc ca
ati tio
on n
FIGURE 2.4. A linear model fit by least squares to the Income data from Fig- FIGURE 2.5. A smooth thin-plate spline fit to the Income data from Figure 2.3
ure 2.3. The observations are shown in red, and the yellow plane indicates the is shown in yellow; the observations are displayed in red. Splines are discussed in
least squares fit to the data. Chapter 7.
The model-based approach just described is referred to as parametric; may be that with such a small number of observations, this is the best we
it reduces the problem of estimating f down to one of estimating a set of can do.
parameters. Assuming a parametric form for f simplifies the problem of
(Theo sách G. James)
estimating f because it is generally much easier to estimate a set of pa- Non-parametric methods
rameters, such as β0 , β1 , . . . , βp in the linear model (2.4), than it is to fit
Non-parametric methods do not make explicit assumptions about the func-
an entirely arbitrary function f . The potential disadvantage of a paramet-
tional form of f . Instead they seek an estimate of f that gets as close to the
ric approach is that the model we choose will usually not match the true
unknown form of f . If the chosen model is too far from the true f , then Easy Data Science @ s-lab.vn - Nguyen Quang
data points as possible without being too rough or wiggly. Such approaches
can have a major advantage over parametric approaches: by avoiding the
our estimate will be poor. We can try to address this problem by choos-
assumption of a particular functional form for f , they have the potential
ing flexible models that can fit many different possible functional forms
to accurately fit a wider range of possible shapes for f . Any parametric
flexible
for f . But in general, fitting a more flexible model requires estimating a
approach brings with it the possibility that the functional form used to
greater number of parameters. These more complex models can lead to a
estimate f is very different from the true f , in which case the resulting
phenomenon known as overfitting the data, which essentially means they
model will not fit the data well. In contrast, non-parametric approaches
overfitting
follow the errors, or noise, too closely. These issues are discussed through-
completely avoid this danger, since essentially no assumption about the
noise
out this book.
form of f is made. But non-parametric approaches do suffer from a major
Figure 2.4 shows an example of the parametric approach applied to the
Đánh giá mô hình (evaluation) – Bài toán Scoring 2.2 Assessing Model Accuracy 31
2.5
12
2.0
– PredicCon
10
1.5
8
Y
1.0
6
0.5
4
Các chỉ số đánh giá khác
0.0
• Root-mean-squared error
0 20 40 60 80 100 2 5 10 20
X Flexibility
• R-squared FIGURE 2.9. Left: Data simulated from f , shown in black. Three estimates of
f are shown: the linear regression line (orange curve), and two smoothing spline
• Absolute error fits (blue and green curves). Right: Training MSE (grey curve), test MSE (red
curve), and minimum possible test MSE over all methods (dashed line). Squares
represent the training and test MSEs for the three fits shown in the left-hand (Theo sách G. James)
panel.
K=5
MACHINE LEARNING
MODELS
Supervised Un-supervised
models models
ü K-mean Clustering
Scoring/ ü Hierarchical Clustering
Classifications
Regression ü Association Rules
- R2 +
&'((* − *)
"
! =1 −
&'((*)
2.5
12
2.0
10
1.5
8
Incom
Incom
Y
e
1.0
6
0.5
4
y
y
it
it
or
Ye
or
Ye
ni
ni
rs ar
Se
so
Se
o fE fE
2
du
0.0
du
ca ca
tio tio
n n
0 20 40 60 80 100 2 5 10 20
X Flexibility
GURE 2.4. A linear model fit by least squares to the Income data from Fig-2.5. A smooth thin-plate spline fit to the Income data from Figure 2.3
FIGURE
e 2.3. The observations are shown in red, and the yellow plane indicates
is shown the
in yellow; the observations are displayed in red. Splines are discussed in
st squares fit to the data. Chapter 7. FIGURE 2.9. Left: Data simulated from f , shown in black. Three estimates of
f are shown: the linear regression line (orange curve), and two smoothing spline
The model-based approach just described is referred to as parametric;
may be that with such a small number of observations, this is the best we fits (blue and green curves). Right: Training MSE (grey curve), test MSE (red
reduces the problem of estimating f down to one of estimating can ado.
set of curve), and minimum possible test MSE over all methods (dashed line). Squares
rameters. Assuming a parametric form for f simplifies the problem of represent the training and test MSEs for the three fits shown in the left-hand
timating f because it is generally much easier to estimate aNon-parametric
set of pa- methods panel.
meters, such as β0 , β1 , . . . , βp in the linear model (2.4), than it is to fit
Non-parametric methods do not make explicit assumptions about the func-
entirely arbitrary function f . The potential disadvantage of a paramet-
(Theo sách G. James)
tional form of f . Instead they seek an estimate of f that gets as close to the
approach is that the model we choose will usually not match the true statistical methods specifically estimate coefficients so as to minimize the
data points as possible without being too rough or wiggly. Such approaches training set MSE. For these methods, the training set MSE can be quite
known form of f . If the chosen model is too far from the true f , then
can have a major advantage over parametric approaches: by avoiding the small, but the test MSE is often much larger.
r estimate will be poor. We can try to address this problem by choos-
assumption of a particular functional form for f , they have the potential
g flexible models that can fit many different possible functional forms Figure 2.9 illustrates this phenomenon on a simple example. In the left-
to accurately flexible
fit a wider range of possible shapes for f . Any parametric
r f . But in general, fitting a more flexible model requires estimating a hand panel of Figure 2.9, we have generated observations from (2.1) with
147
eater number of parameters. These more complex models can lead to a
approach brings with it the possibility that the functional form used to Easy
the true f given by the black Data
curve. TheScience - Nguyen
orange, blue and green Quang
curves illus-
estimate f is very different from the true f , in which case the resulting
enomenon known as overfitting the data, which essentially means they trate three possible estimates for f obtained using methods with increasing
model will not fit the data well. In contrast, non-parametric approaches
overfitting
low the errors, or noise, too closely. These issues are discussed through- levels of flexibility. The orange line is the linear regression fit, which is rela-
completely avoid
noise this danger, since essentially no assumption about the
t this book.
form of f is made. But non-parametric approaches do suffer from a major tively inflexible. The blue and green curves were produced using smoothing
Figure 2.4 shows an example of the parametric approach applied to the
disadvantage: since they do not reduce the problem of estimating f to a splines, discussed in Chapter 7, with different levels of smoothness. It is
come data from Figure 2.3. We have fit a linear model of the form smooth
small number of parameters, a very large number of observations (far more clear that as the level of flexibility increases, the curves fit the observed
income ≈ β0 + β1 × education + β2 × seniority. than is typically needed for a parametric approach) is required in order to data more closely. The green curve is the most flexible and matches the
obtain an accurate estimate for f . data very well; however, we observe that it fits the true f (shown in black)
nce we have assumed a linear relationship between the responseAn andexample
the of a non-parametric approach to fitting the Income data is
SESSION 8: MÔ HÌNH PHÂN LOẠI: LOGISTIC
REGRESSION, DECISION TREE, RANDOM FOREST AND
K-NEAREST NEIGHBORS
0.9
0.7
Purchase
0.5
0.4
0.2
0.0
.0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0
LoyalCH
Probability
0.6
β 0 + β1 X
e 0.5
p = P(Y = 1) =
0.4
0.3
1 + e β 0 + β1 X 0.2
0.1
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
X
1
0.9
0.8
0.7
Probability
0.6
0.5
0.4
0.3
0.2
0.1
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
X
Ø Với số dư trung bìng $2000, xác suất default tăng lên 58.6%
• Có thể chuyển sang score
q Chuyển đổi sang Scorecard:
NGUYEN QUANG 9
151 Easy Data Science - Nguyen Quang
The Classification Setting
Đánh giá mô hình (evaluation) – Bài toán Classification
!For a regression problem, we used the MSE to assess the
• Tỷ lệ phân loại sai: accuracy of the statistical learning method
!For a classification problem we can use the error rate i.e.
• Có 2 kiểu sai (bài toán 2 loại), thông thường được xác định cụ thể hơn: n
Error Rate = ∑ I ( yi ≠ yˆ i ) / n
i =1
Accuracy/Error Rate = True Positive Rate (TPR) False Positive Rate (FPR)
(A+D)/(A+B+C+D) = TP/(TP+FN) = FP/(FP+TN)
False Negative Rate Precision = Recall = TPR
(FNR) = FN/(TP+FN) TP/(TP+FP)
152 Easy Data Science - Nguyen Quang
Đánh giá mô hình (evaluation) – Bài toán Classification
• Với mỗi mô hình phân loại, thông thường có tham số điều chỉnh tỷ lệ giữa True positive (hay Recall) và
False positive
• ROC curve – đường quan hệ giữa True positive và False positive
Mô hình câyComputation
quyết định – parentheses
inside the nguyên islýon the entropy of the class labels within a single contact
value. Note that the conditional entropy is always less than or equal to the base entropy—that is,
• Chia không Hgian các biến
subscribed | marital
≤ Hđộc lập thành các ô độc lập
subscribed . The conditional entropy is smaller than the base entropy when the attribute
• Cách chia, and
gồmthe biến
outcomevà giá aretrịcorrelated.
chia, được xác
In the định
worst saowhen
case, chothe saiattribute
số sau ischia là thấp nhất
uncorrelated with the outcome, 7.1
• ANALYTICAL
VANCED the conditional
Chạy bài toán
THEORYtối ưu entropy equals
AND“Information
METHODS: the base entropy.
Gain”
CLASSIFICATION
The information gain of an attribute A is defined as the difference between the base entropy and the
conditional entropy of the attribute, as step
The next shownis toinidentify
Equation 7-3.
the conditional entropy for each attribute. Given an attribute X ,
its outcome Y , and its value y, conditional entropy HY |X is the remaining entropy of Y given X , form
Given a class X and its label x ∈ X , let P(asx )shownInfoGain
be the = HS of− H A the entropy of X , is defined as (7-3)
inprobability
A
Equation 7-2. x .S|H x,
Vớiin Equation 7-1.
shown
∑ P ( x ) H (Y |X = x )
HY |X =
In the bank marketing example, the information gain of the contact attribute is shown in
H =−∑ P( x )log P( x )
x(7-1)
Equation 7-4. =− ∑ P( x )∑ P(y|x )log P(y|x )
X 2
∀ x ∈X 2
• Cuối cùng,
Equation 7-1 gán
showschothatcác quan
entropy H X sát nằm0trong
becomes when all cùngP( x )một
is 0 orô1.có
Forcùng
a binary giáclassification
trị dự báo(true
Consider= 0.4862
the banking .46661= 0.0201
− 0marketing scenario, if the attribute contact is chosen, (7-4)X = {ce
• orLà phương
false), H X ispháp
zero if“Top-down, greedy”,
P( x ) the probability of có
each thể
label bị
x istắc ở
either cực
zero trị
or địa
one. phương
On the other
telephone, unknown}. The conditional entropy of contact considers hand, H X all three values.
achieves the maximum entropy when all the class labels
Table arethe
7-1 lists equally probable.
probabilities related Fortoathe
binary classification,
contact attribute. The top row of the table d
H X =1 if the probability of all class labels is 50/50. The maximum
probabilities entropy
of each value of theincreases
attribute. Theas the
nextnumber
two rows ofcontain
pos- the probabilities of the
sible outcomes increases. conditioned on the contact.
156 As an example of a binary random variable, consider tossing a coin with known, not Easy necessarily
Data Science - Nguyen Quang
TABLE 7-1 Conditional Entropy Example
fair, probabilities of coming up heads or tails. The corresponding entropy graph is shown in Figure 7-5. Let
x =1 represent heads and x = 0 represent tails. The entropy of the unknown result Cellular Telephone
of the next toss is maxi- Unknown
c07.indd 02:52:36:PM 12/08/2014 Page
m≈ p
• Cần lưu ý
– Chúng ta giả định có tồn tại các nhóm khách hàng (?)
– Phân nhóm chỉ là một phương pháp
Phương pháp K-means Solving (10.9) seems like a reasonable idea, but in order to make it
tionable we need to define the within-cluster variation. There are m
• Xác định trước số cụm/nhóm possible ways to define this concept, but by far the most common ch
involves squared Euclidean distance. That is, we define
p
• Thuật toán K-means sẽ tìm và đặt mỗi 1 ! !
W (Ck ) = (xij − xi′ j )2 , (10
quan sát vào một nhóm |Ck | ′
i,i ∈Ck
j=1
Now there is
no further
change so
Assign points to stop
closest cluster
center
• Do vậy cần chạy thuật toán nhiều lần với khởi đầu
ngẫu nhiên
• Support: SX có cả Y và X
• Lift: Confidence/SX có Y
Thuật toán
• Bước 1: quét các giao dịch và tìm những sản phẩm được mua
• Bước 2: lựa chọn các sản phẩm/nhóm sản phẩm có tần số tối thiểu
• Bước 3: kết nối các sản phẩm/nhóm sản phẩm của bước 2 thành cặp (rule) và tính tần số xuất hiện
• Bước 4: tính các chỉ số khác và lựa chọn rule phù hợp
170 Easy Data Science - Nguyen Quang
Cách sử dụng
• Lọc các cặp mặt hàng có support đủ cao và confidence cao nhất từ trên xuống
• Ứng dụng:
– Bán chéo: Khi KH mua sp bên trái, khuyến nghị sp bên phải
– Khuyến mại: chọn các sp xuất hiện nhiều bên trái để giảm giá
– Bán thêm: chọn các sp xuất hiện nhiều bên phải để trưng bày dễ nhìn hơn
– Bán cặp: tạo combo
– ...
https://www.quora.com/What-is-the-
difference-between-data-analytics-and-
Machine-learning
173 Easy Data Science - Nguyen Quang
Applications
• Self-driving cars
• Drug discovery
• Go player
• Human gene decode
• Robotics
• …
Layer 2: weights
Generalizing
Gradient descent method: uses the gradient to Total Cost: sum over m training observa@on
make an informed step change in w
where
-> Backpropagation
Why?
• Actual images are much more complicated
• Can we increase number of hidden layer?
Convolution
• constant as the filter moves through the
input allows the filter to be trained to
recognize certain features. In the case of
images: lines, edges and other distinctive
shapes. (feature mapping)
• One can use multiple filters at a
convolutional stage. Separately trained
filters each produce their own output, which
may present different key features. (The
output of a convolutional layer can be 3D or
4D (if image is colored)
Pooling
• instead of applying weights the pooling applies
some sort of statistical function over the values
within the window (Most commonly, the max()
function)
• Strides: in max-pooling, stride 2 to avoid overlap -
> down-sampling
• Padding: zero added nodes (never used in max-
pooling
• Reduce the number of parameters in your
network (pooling is also called “down-sampling”
for this reason)
• To make feature detection more robust by making
it more impervious to scale and orientation
changes
Wikipedia
• At the output of the convolutional-pooling layers we have moved from high resolution,
low level data about the pixels to representations of objects within the image.
• We go from neural network classifier onto the end of a trained object detector
• Finnaly, we use a flatten function to turn this output into a single (N x 1) tensor.
K=5
Mô hình
Easy Data Science - Nguyen giám sát: Phân loại
Quang Mô hình không giám sát
188
Tham khảo
• Data Science and Big Data Analytics_ Discovering, Analyzing, Visualizing and Presenting Data
• Business Statistics: A Decision-Making Approach, 6e © 2005 Prentice-Hall, Inc.
• An Introduction to Statistical Learning, Gareth James, Daniela Witten, Trevor Hastie, Robe
• Nina Zumel, John Mount - Practical Data Science with R-Manning Publications (2014)