



Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!




Machine Learning
Outlier : observation which lies at a distance greater than d from at least p percentage of the other observations in the dataset, can be identified with:
z-index method or Clustering
Scaling
Feature extraction: creation of new variables that summarize within themselves the relevant information contained in a subset of the original attributes
PCA - principal components analysis
components has information content almost equivalent to the original dataset
Explanatory capability of the first q PCs
First component:
the solution is the eigenvector associated w/ the largest eigenvalue of the covariance matrix
max w 1
{ w ′ 1 Vw 1 : w ′ 1 w 1 = 1 } → L ( w 1 , λ 1 ) = w ′ 1 Vw 1 − λ 1 ( w ′ 1 w 1 − 1 )
KT T
∂ L ( w 1 , λ 1 )
∂ L ( w 1 , λ 1 )
u 1 λ 1 V
Other components
Iq =
λ 1 +... + λq λ 1 +... + λn
xi ′ j =
xij
10 h x ′ ij =
xij − x min , j x max , j − x min , j (
x ′max , j − x ′min , j ) + x min′ , j
xi ′ j =
xij − μ ¯ j σ ¯ j
⏟ original dataset
PCA P P = { p 1 , ... , p n }
better at explaining data variance
∈ IRn
p i ⊥ p j , ∀ i ≠ j
new basis
and p i = Xw i
zij =
xij − μ ¯ j σ ¯ j
| zij | > 3 suspicious | zij | ≫ 3 outlier
Data discretization: to make continuous variables categorical or to reduce the number of distinct values takes by categorical variables
Measures of heterogeneity - categorical
for other classes : minimum heterogeneity
points
aj fh = 1 fj ≠ h = 0
Categorical graphical analysis - categorical Horizontal or vertical bar charts from the frequencies
aj
pr = empirical density
er m lr
def. quantile : given any value , the p-order quantile is the value : observations will fall on the left of [and the remaining on its right]
p ∈ [ 0 ; 1 ] qp p m qp ( 1 − p ) m
Gini index
Entropy index
H ∑ h = 1
f (^) h^2
H ∑ h = 1
fh log 2 fh
Measures of central tendency - numerical
suitable for symmetric and open classes distributions
density curve multimodal density curves have more peaks, mode has no statistical relevance
aj
Univariate data analysis study the behavior of a j as an independent attribute
z (^) ii nd = z - index
xi − μ ¯ σ ¯
signed distance between any value and μ ¯, normalized on σ ¯
Numerical graphical analysis - numerical Plotted in a histogram
aj
values taken by relative frequencies
relative empirical frequency
H = {1,2,..., H } a j V = { v 1 ,... , vH }
fh =
eh m
mean
median
mode
μ ¯ =
x 1 + x 2 +... + xm m
=
1 m
m ∑ i = 1
xi
xmed^ = x ( m + 1 )/ 2 if m odd
xmed^ =
xm / 2 + x ( m + 2 )/ 2 2 if^ m^ even xmidrange^ =
xma x + xmin 2
Measures of dispersion - aj numerical σ ¯^2 = (^) m^1 − 1 variance
m ∑ i = 1
s i^2 = (^) m^1 − 1
m ∑ i = 1
( xi − μ ¯ )^2
Given
𝒟 dataset a j generic attribute being analyzed a j = ( x 1 , x 2 ,... , xm ) m no. of observations
Scatter plots Loess plots (scatter + local regression) Level curves QQ plots Comparing box plots Time series
Multivariate data analysis Scatter plots matrix Star plots Spider webchart
Bivariate data analysis study the behavior of the pair as a pair Usually explanatory variable, target variable
{ aj , ak } a j a k
fr = marginal frequencies
K ∑ s = 1
trs
gs =
J ∑ r = 1
trs
Analysis of empirical density
With
μ ¯ k =
m
m ∑ i = 1
( xi − μ ¯ ) k
Ias = 0 simmetric :
Ias > 0 skewed to the right Ias < 0 skewed to the left Icurt = 0 ⇒ 𝒩 :
Icurt > 0 emp. density hypernormal Icurt < 0 emp. density hyponormal
vjk = cov( a j , a k ) =
1 m − 2
m ∑ i = 1
( xij − μ ¯ j )( xik − μ ¯ k )
rij = corr( a k , a j ) =
vij σ ¯ j σ ¯ k
Graphical analysis - numerical
local regression and (ii) size of the neighborhood used for the regression [ is a regularizer]
probability distribution, the points will fall on x=y
{ aj , ak } λ α α
𝒩
Measures of heterogeneity - categorical
of in relation to is equivalent to the univariate analysis of
{ aj , ak } T trs { xij = vr }, { xij = us } 𝒟 a j , a k a j a k a j
tr ( V ) = trace of
n ∑ j = 1
vij =
n ∑ j = 1
σ ¯^2 ij V
asymmetry index
kurtosis
Ias =
μ ¯ 3 σ ¯^3
Icurt =
μ ¯ 2 σ ¯^4
Measures of correlation - numerical Linear correlation = covariance std (significant if )
{ aj , ak }
| rij | > 0.
𝒟 dataset a j , a k generic attributes being analyzed a j = ( xj 1 , xj 2 ,... , xjm ); a k = ( xk 1 , xk 2 ,... , xkm ) m no. of observations
Classification - target variable class given , denotes a set of functions
the classification problem is the definition of the hypothesis space and a function which optimally describes the relationship between and
Sm = {( xi , yi ), i ∈ ℳ} : training set , xi ∈ IRnand yi ∈ 𝒟 ℋ f ( x ) : IRn^ → 𝒟 ⇒ ℋ f * ∈ ℋ xi yi
Multicategory classification Every multi category problem can be reduced to a binary problem
Evaluation metrics
1. Accuracy
datasets (not appropriate)
repeated random sampling (obs may appear more than once) holdout method (highly depends on the subsets) k-fold cross validation (more robust) leave one out (k fold, k=m)
KNN - k nearest neighbors - heuristic model knn40=KNeighborsClassifier(n_neighbors=40)
accuracy
Recall (true positive rate)
Precision
F-index
L ( y , f ( x )) = {
0 if y = f ( x ) 1 if y ≠ f ( x )
Acc = 1 −
m
m ∑ i = 1
L ( f ( x i ))
T P T P + F N
% T P T P + F P
%
F =
( β + 1 )^2 tp × prc β^2 prc + tp
The new record is attributed to the class to which the majority of records out of K closest ones belongs ⇒ majority voting
Classification trees - heuristic model
node and max variance between different nodes) between nodes Chosen rule that maximizes the difference in impurity between father and descendant nodes
binary : each node has 2 branches multi split : each node has n>2 branches
Generalized regression
Validation of regression models
Ridge and Lasso regressions relaxes the computation of such that doesn’t have to be invertible
function minimized in the optimization, to penalize too broad regression functions that overfit the problem
But if we add weight to the cost function, and the weights are chosen when the cost function is min
w ̂ X ′ X
λ = 0 λ ≫ 1
X ′ X is not useful if , we have to resort to {
not enough data points > ill posed problem not invertible by nature
covariance of estimators confidence interval
hypothesis test : rejected and model ok
V = cov( w ̂) w ̂ j ±^ tα / 2 vij
H 0 : wi = 0 t ≫ 2, P < 0.05 H 0
h
whgh ( Xi , X 2 ,... , Xn ) + b + ϵ
Significance of the coefficients estimated with SSE minimization are not deterministic, have an associated confidence interval has no significance if its interval contains 0, hypothesis test is conducted such that we can reject the hypothesis of and hence accept the model
w ̂ w ̂
⇒ wi
wi = 0
Extension of classification tech. to regression
Normality and independence of residuals Residuals should not contain any deterministic information about the data, they should be completely random
ϵ ∼ 𝒩 ϵ ∼ 𝒩
L1 - Lasso
L2 - Ridge
min w
R R ( w , 𝒟) = min w
L reg.^ ⏟ term
λ
p
∑ j = 1
| βj |
λ
p
∑ j = 1
β j^2
Confidence interval of predictions (only LS prediction)
F-value
is no relationship between ANY of the independent variables and Y
LEAST 1 independent variable is related to Y
R SSreg / n SS E / m − n − 1
Analysis of variance The model should explain all the target’s variance and not leave any explanatory capability to the residuals SSE : sum squared of residuals RSSreg : sum squared of (variance of prediction) RSStot : sum squared of (variance of real target) F - value : proportion between variance explained by model and variance of residuals
y ̂− μ ¯ y y − μ ¯ y
y ̂±^ tα / 2 σ ¯
m
x − μ ¯ x ∑ m i = 1 ( xi − μ ¯ x )^2
linear correlation of variable j with all other variables
variance inflation factor
R (^) j^2
V I Fj =
1 − R j^2
Multicollinearity In multiple regression, the variables should not be linearly correlated VIF identifies multiple linear relationships among independent variables ( identifies only binary) VIF > 5 : multi collinearity
r
Clustering - unsupervised learning
Classification I
∀ xi ∈! ∀ xi , wij
how much of the data variance has been explained by the model
adjusted R (penalizes addition of variables not correlated to target)
R SSreg R SStot R a^2 dj = 1 − ( 1 − R^2 )
m − 1 m − n − 1
Identification of homogenous groups of records
most methods are heuristic in nature: generate a subdivision into clusters of good quality, although not necessarily optimal,
Standardization strongly affect all clustering algorithms
Affinity measures Clustering is based on the similarity/distance between observations a. Binary attributes a contingency table is built : Jaccard coefficient for non symmetric attributes, distance for symmetric b. Nominal attributes create dummies and treat as binary c. Numerical attributes use one of the distances standardization strongly affects the algorithm Mahalanobis depends on the relationship between variables (covariance matrix) d. Ordinal attributes non numerical attributes that can be placed on a natural ordinal scale then standardized and distance as for numerical attributes
Partition methods
distance matrix
similarity
Jaccard coeff.
Euclidian
Manhattan
Minkowski
dij = dist ( x i , x k ) = dist ( x k , x i ) with i , k ∈ ℳ
sij = ( dij )−^1
dist( x i , x j ) =
q + u n
dist( x i , x j ) =
q + u q + u + v
dist( x i , x j ) =
n ∑ i = 1
( xij − xik )^2
dist( x i , x j ) =
n ∑ i = 1
| xij − xik |
dist( x i , x j ) = p^
n ∑ i = 1
| xij − xik | p
dist( x i , x j ) = ( x i − x k ) V − ik^1 ( x i − x k ) T
δijk = 0 if , :
Δ ijk =
a j binary or nominal :
0 if xij = xik 1 otherwise
a j numerical →
| xij − xjk | max l xlk
dist =
∑ N j = 1 δjik Δ jik
∑ N j = 1 δjik
K-medoids variant of the k-means method, with purpose of mitigating the sensitivity of partitions containing extreme values of , since the mean is sensitive to outliers (i) random obs chosen as medoids, (ii) each obs assigned to the most similar medoid, (iii) replacement of each medoid with a non medoid ( replacement evaluation ) To assess the exchange of each medoid: overall contribution
Tih = (^) ∑ x k ∉ U
Rihk
Tih < 0 pair exchanged Tih > pair not exchanged ⇒ stop
K-means chosen k centroids (ii) each obs to the most similar centroid, (iii) barycenter of clusters computed = new centroid (iv) each obs reassigned to the closest centroid COG of the centroid changes at each iteration, when it doesn’t change anymore it means it has reached a stable point stop
unbalanced, (ii) varies in density, (iii) non convex shapes
min w 1 ,…, w k
K ∑ u = 1
∑ (dist( xi ,^ w h ))
2
Given a dataset of m observations, each representer by a vector in n- dimensional space, partition methods construct a subdivision of into a collection of non- empty subsets
𝒞 = { C 1 , C 2 , …, CK }, K ≤ m
Hierarchical methods
criteria
The chosen distance affect the clustering Minimum distance = single linkage Maximum distance = complete linkage Mean distance Ward distance : minimum variance method computes all distances and merges clusters which lead to the cluster with minimum variance among the possible ones
Agglomerative methods - bottom up Each obs is a cluster in the beginning Two clusters with minimum distance are merged at each iteration (level) Everything ends up in a cluster Cut dendrogram the required level
Divisive methods - top down All obs in the same cluster Cannot compute all possible splits, so the two furthest away are identified, and each obs assigned to the closest
strongly affected by outliers (need to be removed before)
Evaluation of clustering How many clusters? Those that explain a sufficient variance of the data Cohesion : how similar obs in the same clusters are Separation : how different obs in different clusters are Silhouette : combination of how well an attribute is cohesive with other obs in its cluster and separated from obs of other clusters
Identification of recurrences and patterns within a large set of transactions
Empirical frequency
Association rules Rule: implication of the type ( if Y is true, then Z is true ) Probabilistic rule : implication of the type ( if Y is true, then Z is true with probability p)
p X
based on distance between clusters , not single points
dist( Ch , Cf ) = min x i ∈ Ch , x k ∈ Cf
dist( x i , x k )
dist( Ch , Cf ) = max x i ∈ Ch , x k ∈ Cf
dist( x i , x k )
dist( Ch , Cf ) =
∑ x i ∈ Ch
∑ x k ∈ Cf
dist( x i , x k )
card{ Ch }card{ Cf }
coes( Ch ) = (^) ∑ x k ∈ Ch , x i ∈ Ch
dist( x i , x k )
sep( Ch ) = (^) ∑ xk ∈ ch , xi ∈ Cf
dist( x i , x k )
silh( x i ) =
vi − ui max( vi , ui )
1 ideal 0 overlapping clusters − 1 worst case
f ( L ) = card{ Ti : L ⊆ Ti , i = 1,2,…, m }
p = conf{ L ⇒ H } =
f ( L ∪ H ) f ( L )
s = supp{ L ⇒ H } =
f ( L ∪ H ) m l = lift{ L ⇒ H } =
conf{ L ⇒ H } f ( H )
=
f ( L ∪ H ) f ( L ) f ( H )
Association rule: probabilistic implication with the meaning ‘ if L is contained in T, then also H is contained in T with probability p ’ strong association rule
only strong rules are considered when analyzing a dataset to only extract strong rules, we use
s > s min p > p min