Docsity

Notes for Machine Learning Exam Professor Maria Felice Arezzo, Dispense di Machine learning

Toggle sidebar
bg1
24/02
What is statistics?
Statistics is the science concerned with the collection, analysis, interpretation, and
presentation of data.
Its purpose: To transform raw data (numbers, categories) into useful information for
making decisions under uncertainty.
Its nature: It is based on mathematics, specifically probability theory, to quantify the
uncertainty and variability of the real world.
Historically, statistics is divided into two broad areas:
1. Descriptive Statistics: Describes, summarizes, and visualizes the main
characteristics of a collected dataset (e.g., through graphs, means, percentages).
”What do these data tell us?”
2. Inferential Statistics: Uses a sample of data to draw conclusions, make predictions,
or make decisions about a much larger group (the population). ”What can I infer from
these data?”
To perform inference, it is crucial to understand this distinction:
Population: The entire group of individuals or objects we want to study (e.g.,all Italian
citizens). It is often too large or expensive to analyze entirely.
Sample: A subset of the population selected for analysis (e.g.,1,000 randomly chosen
Italian citizens). For inferential statistics to work, the sample must be representative of
the population.
The ”Building Blocks” of Statistics:
The Statistical Unit
Before even measuring data, we must define on whom or on what we are performing
the measurement. What is the Statistical Unit? It is the basic element of observation. It
is the single entity (person, object, animal, or event) that carries the characteristics
(variables) we want to study and analyze.
How to recognize it in practice? Simply ask yourself: ”On whom or what am I drawing
my conclusions?” Practical Examples: Income survey: The unit is the individual citizen
(or family). Train delay study: The unit is the single train journey. Factory quality
control: The unit is the single manufactured part.
Variables
The data we analyze are called variables and are divided into two macro-types:
Qualitative (Categorical) Variables
-Express a quality or a category.
-Nominal: Without an inherent order (e.g., eye color, city of residence).
-Ordinal: With a logical order (e.g., educational level, degree of satisfaction).
Quantitative (Numerical) Variables
-Express a measurable quantity.
-Discrete: Countable values (e.g., number of children, number of cars).
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b

Anteprima parziale del testo

Scarica Notes for Machine Learning Exam Professor Maria Felice Arezzo e più Dispense in PDF di Machine learning solo su Docsity!

What is statistics? Statistics is the science concerned with the collection, analysis, interpretation, and presentation of data. Its purpose: To transform raw data (numbers, categories) into useful information for making decisions under uncertainty. Its nature: It is based on mathematics, specifically probability theory, to quantify the uncertainty and variability of the real world. Historically, statistics is divided into two broad areas:

  1. Descriptive Statistics: Describes, summarizes, and visualizes the main characteristics of a collected dataset (e.g., through graphs, means, percentages). ”What do these data tell us?”
  2. Inferential Statistics: Uses a sample of data to draw conclusions, make predictions, or make decisions about a much larger group (the population). ”What can I infer from these data?” To perform inference, it is crucial to understand this distinction: Population: The entire group of individuals or objects we want to study (e.g.,all Italian citizens). It is often too large or expensive to analyze entirely. Sample: A subset of the population selected for analysis (e.g.,1,000 randomly chosen Italian citizens). For inferential statistics to work, the sample must be representative of the population. The ”Building Blocks” of Statistics: The Statistical Unit Before even measuring data, we must define on whom or on what we are performing the measurement. What is the Statistical Unit? It is the basic element of observation. It is the single entity (person, object, animal, or event) that carries the characteristics (variables) we want to study and analyze. How to recognize it in practice? Simply ask yourself: ”On whom or what am I drawing my conclusions?” Practical Examples: Income survey: The unit is the individual citizen (or family). Train delay study: The unit is the single train journey. Factory quality control: The unit is the single manufactured part. Variables The data we analyze are called variables and are divided into two macro-types:  Qualitative (Categorical) Variables -Express a quality or a category. -Nominal: Without an inherent order (e.g., eye color, city of residence). -Ordinal: With a logical order (e.g., educational level, degree of satisfaction).  Quantitative (Numerical) Variables -Express a measurable quantity. -Discrete: Countable values (e.g., number of children, number of cars).

-Continuous: Measurable values within a range (e.g., height, weight, temperature). Fundamental Summary Statistics In descriptive statistics, we summarize data using two types of measures:

  1. Measures of Central Tendency (Where is the data centered?) Mean (μ): The sum of all values divided by their number. Median: The middle value when the data is sorted. Mode: The value that appears most frequently. Quantiles: Threshold values that divide an ordered dataset into groups of equal size (e.g., quartiles, percentiles).
  2. Measures of Dispersion (How ”spread out” is the data?) Variance (σ2) and Standard Deviation (σ): Indicate how much the values deviate, on average, from the mean. Interquartile Range (IQR): The distance between the third and first quartile (Q3 − Q1). It measures the spread of the middle 50% of the data and is robust to extreme values (outliers). Gini Index: Measures dispersion for categorical variables. Summary Statistics: Measures of Shape Besides central tendency and dispersion, it is essential to understand the shape of our data distribution. We use two main indicators:
    1. Skewness Measures the lack of symmetry in the data relative to the mean.  Positive (Right-skewed): The ”tail” of the distribution stretches towards higher values (e.g., income distribution).  Negative (Left-skewed): The ”tail” stretches towards lower values.  Symmetric: The data is distributed evenly like a mirror image (the index is equal to 0).
    2. Kurtosis Measures the ”heaviness” of the distribution’s tails, i.e., how frequent extreme values (outliers) are compared to a normal distribution.  Leptokurtic: ”Fat” tails and a very sharp central peak (high probability of extreme values)  Platykurtic: ”Thin” tails and a flatter shape (low probability of extreme values) Graphical Representations: Categorical Variables To show the frequency (or percentage) of categories, we mainly use two charts:  Bar Chart X-Axis: Categories. Y-Axis: Frequencies. The bars are separated from each other. Pros: Easy to compare heights.

Y-Axis: Dependent variable (Quantitative variable). What does it allow us to see? The behavior and distribution of a quantitative variable across different categories. 25/ What is Machine Learning? Classic Definition (Arthur Samuel, 1959): ”The field of study that gives computers the ability to learn without being explicitly programmed.” Instead of writing rigid rules (if- then-else), we provide the computer with historical data and expected outcomes. The algorithm autonomously ”learns” the rules from the data. Main Objective: To generalize from experience in order to make accurate predictions on future, unseen data. Both Machine Learning (ML) and Statistics work with data to extract knowledge, but they stem from different disciplines and philosophies:  Statistics: Born from Mathematics. Its primary focus is Inference, meaning understanding the data and explaining the relationships between variables.  Machine Learning: Born from Computer Science and Artificial Intelligence. Its primary focus is Prediction, meaning achieving practical and highly accurate results. Difference 1: the objective  Statistics: ”The Why” Explains the mechanism that generated the data. Assesses the impact and significance of every single variable. Ex: To what extent do square footage and location influence a house’s price?  Machine Learning: ”The What” Builds a model to make perfect predictions. The model can be a ”black-box”, as long as it performs well. Ex: What will be the exact market price of this specific house? Difference 2: the approach to data  Statistical Models: Make strong a priori assumptions about the data (e.g., the distribution must be normal, variables must be independent). If the data does not meet these assumptions, the model loses validity.  ML Algorithms: Make very few mathematical assumptions. They adapt to the inherent structure of the data and are designed to handle Big Data and highly complex or non-linear relationships, where traditional statistical models struggle.

CLUSTER ANALYSIS

The aim of cluster analysis is to identify groups (clusters) of points that are as homogeneous as possible within themselves and different from each other. Obviously, the homogeneity/heterogeneity of the groups needs to be assessed against a set of characteristics (variables). Note that the number of groups is not known a priori. Supervised learning The dependent variable (Y) stands above The independent variable (X) is used to understand the variable Y Unsupervised learning Y variable doesn’t exist Goal is to understand something All the variables at the same level This is where we do clustering - clustering is: there is a group that behaves in a similar way - Taking the data and understand, how can I split the data in cluster, try to identify groups, that behave inside the group similar, we don’t know how many groups there are Within the framework of cluster analysis, three types of techniques can be distinguished: 1 Hard clustering : we partition the initial n elements into k groups; Partition: divide, a set of statistical units - divide into sub sets, each element in a subset belongs to one subset only, any pair of subset is a no set, no common individuals, Union: all subsets together No overlapping in clusters, so no uncertainties its either 1 or 0 2 Soft clustering: clumping (or overlapping clustering): each of the n elements is assigned a number indicating the degree to which it belongs to a given group (1, 0, 0.5: belongs, does not belong, belongs also to another group or groups).;

To be concerned about is to minimise the eternal inertia or maximise the external inertia Barycentre; g = General barycentre: mean, something that stands in the middle, tell me what on average ppl do K group centres: Point mass: Group mass: II norm of a vactor x1-g Inertia: Within + between K describes the different Groups mi= mass of each point, ist die gewichtung xi= is a single grade g= gK= very center of each group, point that stands in the middle, its the mean is the barycentre Inertia= is about the distance between each point and the barycentre, compute the distance between each point and the barycentre, its a measure that tells you how distant all the points are from the common centre, is the variance in a multidimensional space Overall inertia = deviance. Take each grade, subtract the general barycentre, square, do it with every grade 28- 28.8 square - do with every number Within Inertia: within each group is for example Quantitative inertia, economic inertia, law inertia; tell me how consistently a thing is, Overall within ineratia= all inertia within summed up Summing up within inertia will not give you the general inertia Between inertia = tells me how different the groups are, to compute is I take a representative of each group the within barycentre , subtract the general centre - square it - multiple the amount of single courses Tells me how separated the groups are T = General inertia is fixed W and B is flexible - One increased the other one decreases and vice versa Those lie on the groups and if I change that it varies, you change the grouping, the number of allocation to the groups then I am altering the allocation between the within inertia and the between inertia If i increase the number of groups - if I have 20 groups with only one value/variable - within inertia is 0 Using clustering you don’t know the amount of groups and what belongs to the group

Minimise the within inertia - the between inertia is maximised Individuals and variable Multidimensional data = using more than one elements / components Standartising = you can compare easier - gleiche Vergleichsbasis Barycentres = general is both (time and grade) 0 - because multidimensional space Each point is described by a pair values

Tool: Concept of distance Distance is a function: This definition is very general and fails to explain how to calculate the distance between two points. Distance is a function that makes R(high 6) to R but it has to have some properties Properties that must be satisfied for it : #1 The number must be positive or 0 #2 symmetry: the distance between A and B must be the same as prom B to A – #3 meaning the distance between A & B is 0 B & A is the same #4 The distance of A and B less than or equal to the sum of A & C + B & C Depending on the nature of the variables: All Numerical variables: could compute the minkowski distance - xi is a point, here 2 points - xis= one point, the s goes from one to p, - Landa we have to choose, normally 1 or 2 (xi-xi)^2 „do this for all the columns and then sum them P is the end of all the variables (maximum of variables you have)

Mahalanobis-> takes into account the correlation of the variables Lambda equal to 1 = Manhattan distance When to use: Lots of outliers Lambda equal to 2 = euclidean distance When to use: If you don’t have much outliers

a first partition is determined in which each individual belongs to the group for which the distance to the provisional centre is minimum; the internal inertia (which we call V(0)) is calculated, considering as barycentres the K provisional centres; we recalculate the new barycentres gk(0); the internal inertia W(0) is recalculated; step 1: we reallocate the individuals so that the distance from each barycentre found in step 0 (gk(0)) is minimum; the internal inertia (which we call V(1)) is calculated taking the centre of gravity (gk(0)) as the centre of gravity; we calculate the new barycentre (gk(1)); the internal inertia W(1) is recalculated; The next steps 2,3···t are obtained by repeating the steps illustrated in step 1. The process stops when W(t) −V(t) = 0 or when W(t)−V(t) < τ, where τ is a threshold value. The sense is that the algorithm ends, when no more individuals (or only a few) move from one group to another and therefore thus the internal variance does not change (or changes little). The more you repeat the process, the algorithm will converge and the barycenter will stabilize, I wouldn’t have to change the partition of the points The K means algorithm The most widely used non-hierarchical algorithm is the K-means algorithm, which was developed by MacQueen in 1967. The K-means algorithm differs from Forgy’s in that the calculation of the new barycentre is carried out immediately after the reallocation of individuals to the new group. One of the key advantages of the K-means algorithm is its ability to converge much more rapidly than Forgy’s algorithm. The drawback of non-hierarchical methods is that the number of groups to be formed is chosen at the beginning by the researcher and cannot be altered.

The Mcqueen algorithm is faster because it doesn’t compute on the old barycenter the new inertia, but it directly uses the new one Double computing of the new inertia makes things slower (and it’s harder when you have lots of data, no waste of time, that’s way the Mcqueen algorithm was proposed) Clustering it’s about grouping elements but we don’t know how many groups, I have to decide at the beginning how many groups I want (disadvantage) Non hierarchical methods are faster and work better with lots of data (advantage) Hierarchical methods One of the defining characteristics of such algorithms is that they produce a hierarchical partitioning of data in the form of a tree structure. This addresses the limitation of non-hierarchical methods, whereby the number of groups is predetermined, rather than being determined at the end of the analysis. There are two main types of hierarchical algorithms: (we won’t focus on the splitting) 1 Agglomerative (or ascending) algorithms 2 Splitting (or descending) algorithms The agglomerative methods can be further divided into the following categories: 1 The basic agglomerative methods involve one aggregation at a time. 2 The simultaneous agglomerative methods involve several aggregations at a time (not covered in the course). Basic agglomerative methods The following is a step-by-step guide to the operation of a basic aggregative algorithm: 1 the two individuals (referred to as p and q) with the shortest distances between them are aggregated to form the first cluster (h); 2 we define the criterion with which to calculate the distance between h1 and the remaining n − 2 individuals; 3 aggregates h with the least distant individual (say r); 4 we iterate the process by repeating steps 2 and 3 until all the individuals have been aggregated. The method used to calculate the distance between two objects is a defining feature of this type of algorithm.

Compute the distances between each possible pair Find which pair is most similar (choose the smallest one, it means that they are the closest) The closest will stop being individuals and will aggregate to form a new cluster Compute a new distance matrix with the individuals remaining Problem: distance between the individuals and the cluster-> there are several proposals: minimum, maximum, average When I obtain my new matrix, the process will start again 17/ Dendrogram and groups number We can represent the entire agglomeration process in a graph (dendrogram): Shows me how the algorithm worked all over the way, shows how the merging occurred X=individuals (ex: Regions) Y=index, a number that tells me at what level the individuals merge together Horizontal segment= converge into a cluster The within variance approaches the overall variance moving upwards the Y axis Within variance= close to zero= variability within the cluster is low, individuals behave similar, within variance should be low Increase in the within variance is contained, at some point it explodes, so cut it before the within variance explodes The five individuals are represented on the horizontal axis, while the vertical axis depicts an index denoting the distances at which the aggregation occurs. The newly formed individuals resulting from the aggregation process are located within the tree. What methodology should be employed to determine the optimal number of final clusters? In general, the objective is to identify the partition that is characterized by the fewest number of clusters with the highest degree of internal homogeneity. These

two requirements are mutually exclusive: if the objective is to minimize the number of groups, the nodes at the top of the tree will be removed; conversely, if the aim is to maximize internal homogeneity, the nodes at the bottom will be removed. A statistical criterion that could be employed is to select the number of groups for which the index jump is at its maximum. As illustrated in the figure above, if we go from 1 group to 2 groups, the index exhibits a variation of 9 − 4 = 5. If we proceed from 2 to 3 groups, the index varies by 4 − 2 = 2. If we go from 3 to 4 groups, the index varies by 2 − 1 =

  1. Therefore, the optimal cut-off point will be the one that leads to the formation of 2 groups (just above index value 4). Divisive algorithms These methods start from the total set of n units and proceed by binary partitions. At each step of the procedure, the assignment of an individual to one cluster or another depends on the optimization of an internal variance function of the groups. The method is characterized by the choice of the function to be optimized. From a sample of n individuals on whom p variables have been measured, it is always possible to construct the variance and covariance matrix. The trace of this matrix gives the total variance (inertia) of the phenomenon. By splitting the individuals into two groups, we can calculate two matrices of variances and covariances, which we will call W1 and W2. It is also possible to define the following matrix W = W1 + W2. It is easy to realize that, the trace of W is the internal variance of the two groups. Cavalli-Sforza algorithm : at each step, the algorithm searches for the bipartition that minimizes the trace of W. Mixed methods Problem k means= we don’t know the number of cluster at the beginning, we have to decide it in advance Hierarchical clustering: pros-> don’t have to decide how many clusters do we have, we see it at the dendrogram, I can decide afterwards the number of clusters. Cons -> if there is a lot of individuals, dendrogram is difficult to read. Mixed methods use both in combination hierarchical an non hierarchical methods Mixed methods A dataset with lots of individuals
    1. Run a K mean algorithm with 100 initial centers- petition with 100 groups
    2. Treat the 100 groups as one individual
    3. Use a hierarchical algorithm to cluster the individual
    4. Build a dendrogram
    5. Cut the dendrogram at a certain number They are a combination of hierarchical and non-hierarchical methods, using both depending on the stage of the algorithm. The algorithm involves the following steps: 1 A non-hierarchical method is used with a large number of initial centres;

EXAMPLE

If we did not use any information on the characteristics of the client (i.e. Savings, Wealth and Annual Income), we would conclude that the best decision rule (in the sense of the one that reduces the probability of misclassifying a new client) corresponds to Low. In fact, 5/8 clients in the sample at our disposal represent this mode. If this is the decision rule (associates each new customer with a Low credit risk), then the probability of misclassification is 3/8 and the misclassification rate is 37.5%. Now we use covariates to improve our prediction. We use Wealth (without explaining why for the moment) and divide our statistical units into two groups: those with low wealth and those with medium or high wealth. With this partition induced by the use of the variable Wealth, we obtain the following two groups Group 1: Clients B, G with 100 per cent High Credit Risk Group 2: Clients A, C, D, E, F with 83.5 per cent of Low Credit Risk

The decision rule adopted (separates clients with low Wealth from the others and classifies those with low Wealth as having High risk and others as having Low risk) has the following misclassification rate: hence, the misclassification rate is 16.7 per cent. This means that using the Wealth information, we reduced the misclassification rate by about 20 percentage points. We now use the information on Savings and split those with high savings from the others (we still say nothing about how we made this decision). The tree becomes: The last step of the algorithm takes wealth into account and separates statistical units with medium or low wealth from those with high wealth: