




















































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 is described as ”design methodologies to extract patterns from data, ideally without much domain-specific expertise”.
Big Data is described as ”data whose scale, diversity and complexity require new architectures, techniques, algorithms and analytics to manage it and extract value and hidden knowledge from it”. The 5Vs of Big Data:
Big data challenges:
Data Science is described as “extracting meaning from large quantities of data”. The data science process begin in the real world, observing raw data, processing and cleaning it, then apply ML/stats to have a model that can interact with the real world. And so on with this circle. Data generation can be passive (structured data), active (semistructured or unstrunctured data) or automatic production (sensor-based devices).
“AI is machines mimicking human intelligence to perform tasks”. AI is like electricity, it fuels our planet. Intelligence involves learning, AI involves ML.
“Algorithms that enables computers to learn and make decisions without being explicitly programmed”. ML is about fitting models to data to make predictions or forecasts. There are mainly 2 kind of learning:
Anyway, there are still some open issues like social impact like interpretability and trasparency of the analysis process or bias in algorithms and data (algorithm can learn also prejudices and biases from data, leading to unfair outcomes) or privacy preservation. Then there are also many technical issues like scalability, data dimensionality, complex data structures, data quality, streaming data.
A dataset is a collection of data, a tabular representation of data that includes rows (1, ..., m) and columns (1, ..., n), where rows correspond to objects, records, point, case, sample, entity, or instance, while columns are the attributes. The size of the dataset has an impact on the choice of the analyses. Some algorithms require considerable hardware resources when applied to large datasets, in some cases it is not possible to execute them at all. There are solutions to reduce the size of the dataset preserving the completeness of the data like the data sampling can reduce the dataset size in terms of number of rows and the feature selection can reduce the number of attributes. Each column of the dataset represents one attribute/feature, data exploration can be performed in a univariate (one single columns) or multivariate (more columns) fashions. For further analysis consider the following basic information for each attribute: unit of measurement, attribute type (categorical, not numerical or fixed number of possible values, or numerical, discrete or continuous) and attribute domain (it is a good practice to verify if the attribute values satisfy the domain-driven constraints). Let’s consider a random variable X, a variable that can take on different values, each with a certain probability, in a random or uncertain manner. This variable is a theoretical distribution that can be characterized by many numbers like the mean value, the standard deviation, and so on. Consider a Gaussian random variable X ∼ N(0, 1). This variable is characterized by:
−∞ fX^ (x)dx, but for the normal Gaussian is fX (x) = √^12 π e−^
x 22 , being an integer, the probability is the area between the curve and the limits of the integer (for a non-normal Gaussian (X ∼ N (μ, σ) the PDF is fX (x) = (^) σ√^12 π e−^
(x−μ)^2 2 σ^2 );
−∞ xfX^ (x)dx, but for the Gaussian is −∞;
But in the reality of data, we don’t have these kind of distributions and formula ready to describe the data we are working on. We just have data. This data represent an empirical distribution, the distribution function associated with the empirical measure of a sample. Obviously, also in this case we can characterize the distribution with the value we talked about before, where:
μ =
m
X^ m
i=
xi (1)
σ =
v u u t 1 m − 1
X^ m
i=
(xi − μ)^2 (2)
2.1.2 Cumulative Distribution Function
A cumulative distribution function (CDF), often denoted as F(x), is used to describe the probability distribution of a random variable and provides information about the probability that the random variable takes on values less than or equal to a specific value x.
FX (x) = P (X ≤ x) (4)
P (a ≤ X ≤ b) = FX (b) − FX (a) (5)
The CDF also provides a visual representation of the shape of the distribution, probable values/intervals appear as steep or vertical sections of the CDF. Remember that from the fundamental theorem of Cal- culus, PDF is the derivate of CDF:
fX (x) =
dFX (x) dx
2.1.3 Empirical Cumulative Distribution Function
The ECDF is an estimate of the CDF that generated the points in the sample. To evaluate ECDF(x) for a particular value of x, we compute the fraction of values in the distribution less than or equal to x. The ECDF is a step function that jumps up by 1/m at each of the m data points. E.g. about 10% of pregnancies are shorter than 36 weeks, and about 90% are shorter than 41 weeks. The CDF also provides a visual representation of the shape of the distribution. Common values appear as steep or vertical sections of the CDF; in this example, the mode at 39 weeks is apparent. There are few values below 30 weeks, so the CDF in this range is flat.
2.1.4 Percentiles
Percentile indicates the value below which a given percentage of observations in a group of observations falls. In essence, percentiles divide a dataset into equal or specified intervals, making it easier to analyze and compare data. For example, the 25th percentile (also known as the first quartile) represents the value below which 25% of the data points fall, the 50th percentile (also known as the median) represents the value below which 50% of the data points fall, and the 75th percentile (the third quartile) represents the value below which 75% of the data points fall. Quartiles are a specific set of percentiles commonly used to understand the spread and central tendency of data. The first quartile (Q1) is the 25th percentile, the second quartile (Q2) is the 50th percentile
(median), and the third quartile (Q3) is the 75th percentile. These quartiles are useful for dividing the data into four equal parts, providing insight into the spread and symmetry of the distribution. Expressing data in terms of percentiles allows for a comprehensive representation of the entire distri- bution. You can see how data is distributed across different segments of the dataset. Identifying outliers is one of the valuable applications of percentiles. Outliers are data points that fall in the extreme lower or upper ends of the distribution. For instance, values in the first percentile (1st percentile) and the last percentile (100th percentile) are extreme outliers. Detecting and dealing with outliers is crucial for data cleaning and ensuring statistical robustness.
2.1.5 Boxplot
A boxplot, also known as a box-and-whisker plot, is a standardized way to visualize and summarize the distribution of a dataset. It provides a graphical representation of key statistical values, making it easy to understand the spread and central tendency of the data. Here are the key components of a boxplot and their meanings:
2.2.1 Correlation
Correlation is a statistical measure that quantifies the strength and direction of the relationship be- tween two data objects or variables. It is a fundamental concept in data analysis and plays a crucial role in various aspects of data exploration, understanding data properties, and optimizing data-driven algorithms. Correlated features could be removed simplifying the next analytics steps. A correlation is a statistic intended to quantify the strength of the relationship between two variables. Possible way to compute correlations are the covariance (in order to compare two variables, they must have the same unit of measurement, alternatively, they must be normalised), Pearson (solves the problem of normalization, only detects linear correlation) and Spearman.
where x and y are columns, they are vectors. In the covariance formula we need to remove the sample
mean to understand, for example, if x is large, y is large as well (if the trend is the same).
sxy sxsy
is
the Pearson correlation coefficient. If it is -1 means that the two variables are not correlated (the first is getting bigger, the second one is getting smaller); while if it is 1 means that the two variables are correlated (the first is getting bigger, the second one is getting bigger as well). Of course, correlation can be also different from the linear one: it can be, for example, nonlinear (y = x^2 ). Anyway there are some types of nonlinear correlations that Pearson’s correlation can’t detect. The Spearman index or Spearman’s rank uses the variables rank instead of Pearson that uses the variables themselves. As rank, we define the order of the variables (the position) in a vector in order to list the sorted vector (e.g x = [3, 0, 1], the rank is R(x) = [3, 1, 2]). It assesses how well the relationship between two variables can be described using a monotonic function. In some cases the Spearman index allows to find a correlation when the Pearson index returns a value close to 0. It is defined as:
fs = ρR(x),R(y) =
cov(R(x), R(y)) σR(x)σR(y)
if all m ranks are distinct integers, it can be computed using the formula:
rs = 1 −
(R(xi) − R(yi))^2 m(m^2 − 1)
This is an example:
So, the trend is nonlinear. If you plot the 2 coordinates, you will see that the curve is nonlinear. Spearman’s rank is 1 when two variables are correlated by an increasing monotonic function, -1 if the function is decreasing monotonic, 0 if there isn’t a monotonic function correlation.
2.2.2 Plots
The simplest way to visually check for a relationship between two variables is a scatter plot. This plot is ok for the first visualization of data, but it is not so good for deep study: you can’t see how many points are in an area with many many points. Moreover, some scatter plot may be affected by rounding and conversion (1): a mathematical process of approximating a numerical value to a specified level of precision or a specific number of decimal places. A possible solution is to jitter the data (2), which means adding random noise to reverse the effect of rounding off. Then adding alpha parameter (transparency) to each point (3) in order to retrieve density information (darker zones correspond to higher density zones. Scatter plot can be, then, converted into hexbin plot. The hexbin plot uses hexagonal bins that are colored according to how many data points fall in it. This is similar to a 2D histogram (density representation).
Scatter Plot Percentiles, sometimes called a percentile plot or a percentile scatter plot, is a tech- nique used to visualize the relationship between two variables when one of the variables is categorized or
missing record can exist. Reasons for missing values are information is not collected (e.g., people decline to give their age and weight), attributes may not be applicable to all cases (e.g., annual income is not applicable to children). How can I handle missing values? Eliminate data objects or variables, estimate them (time series of temperature) or ignore them during analysis. Data set may include data objects that are duplicates, or almost duplicates of one another. Major issue happen when merging data from heterogeneous sources (different words/abbreviations for the same concept e.g., Street, St.). Data cleaning is needed.
Similarity is a numerical measure of how alike two data objects are, it is higher when objects are more alike, it often falls in the range [0,1]. Dissimilarity is a numerical measure of how different are two data objects, it is lower when objects are more alike. Often minimum is 0. Often called distance metric: but non every dissimilarity is a distant metric, it depends on its properties. Similarity and dissimilarity between two objects, x and y, with respect to a single, simple attribute.
3.4.1 Euclidean distance
d(x, y) =
v u u t
Xn
k=
(xk − yk)^2 (10)
where n is the number of dimensions (attributes) and and are, respectively, the k th attributes (compo- nents) of data objects x and y. Standardization might be applied, if scales differ.
3.4.2 Minkowski distance
d(x, y) = (
X^ n
k=
|xk − yk|r^ )
(^1) r (11)
where r is a parameter.
d(x, y) =
X^ n
k=
|xk − yk| (12)
d(x, y) = max k |xk − yk| (13)
3.4.3 Properties of a distance metric
A distance d is called metrics if satisfy the following properties for all points on the metric space:
d(x, y) > 0 (15)
d(x, y) = d(y, x) (16)
d(x, z) ≤ d(x, y) + d(y, z) (17)
3.4.4 Mahalanobis distance
It measures the distance between two points with respect to a probability distribution with covariance ma- trix S. The Mahalanobis distance is thus unitless, scale invariant, and takes into account the correlations of the data set.
d(x, y; S) =
q (x − y)T^ S−^1 (x − y) (18)
where S is the sample covariance matrix, which can be calculated putting on the main diagonal the covariance calculated on the same point (the variance), and in the other parts all the possible covariance couple. That’s an example, on the first row cov(x, x)cov(x, y), on the second row cov(y, x)cov(y, y). Than, invert this matrix. If each or these axes is re-scaled to have an identity covariance matrix, then the Mahalanobis ditance corresponds to standard Euclidean distance in the transformed space. That’s the way to calculate the inverse of a matrix: Looking at the picture we see that the distance AB is smaller because their axe goes in a direction that is not the one where the majority of the points are.
When (feature) dimensionality increases, data becomes increasingly sparse in the space that it oc- cupies. Definitions of density and distance between points, which is critical for clustering and outlier detection, become less meaningful. This problem is called curse of dimensionality. Adding dimen- sions to a fixed number of elements, get the distance bigger between the elements. Feature subnet selection is a way to reduce dimensionality of data in two different possibilities: aggregating redundant features in one or more other attributes, or even eliminating irrelevant features useless fort the data mining task. Recursive feature elimination: assign weights to features, selects features by recursively considering smaller and smaller sets of features. First, the estimator is trained on the initial set of features and the importance of each feature is obtained, the least important features are pruned from current set of features. That procedure is recursively repeated on the pruned set until the desired number of features to select is eventually reached. It can be important to exploit feature importance of interpretable models or select automatically features detecting the most important ones (PCA, SVD).
3.5.1 Feature engineering
A feature is a numeric representation of an aspect of raw data. Feature engineering is the act of extracting features from raw data and transforming them. Formats that are suitable for the machine learning model. Feature learning: automate the choice of finding good features. According to the type of data under analysis different feature engineering techniques are needed, structured (numerical data, categorical data), unstructured (text, images, signals), mixed. Basic types of feature engineering techniques include Data transformation, Normalization, Discretization, Binarization.
3.5.2 Data transformation
Data transformation is the process of converting data from one format to another. Why do we transform data? Non numerical data is difficult to analyze if not transformed into numerical, Capture the important information in a data set much more efficiently than the original attributes, To better visualize the data (e.g. transform linear scale to logarithmic scale in audio context).
3.5.3 Discretization
Discretization is the process of converting a continuous attribute into an ordinal attribute. A potentially infinite number of values are mapped into a small number of categories. Examples of unsupervised discretization techniques:
3.5.4 Binarization
Binarization maps an attribute into one or more binary variables. Continuous attribute: first map the attribute to a categorical one. Categorical attribute can be mapping to a set of binary attributes or one-hot encoding. One-Hot Encoding use a group of bits, each bit represents a possible category, if the variable cannot belong to multiple categories at once, then only one bit in the group can be 1.
3.5.5 Normalization
An attribute transformation is a function that maps the entire set of values of a given attribute to a new set of replacement values such that each old value can be identified with one of the new values (some simple functions: xk, log(x), ex, |x|. Normalization or feature scaling refers to various techniques to adjust to differences among attributes in terms of mean, variance, range, etc. Min-Max Normalization bring all values into the range [0,1], is sensitive to outliers and retains the shape of the distribution, but change the intervals.
x′^ =
x − xmin xmax − xmin
Standardization, another kind of normalization, is not bounded to a certain range, it is used when we want to ensure zero mean and unit standard deviation. Gaussian is also standardized but standardization does not create a Gaussian, data remain of the same distribution but with zero mean and unit standard deviation.
x′^ =
x − μ σ