











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!












Introduction to Artificial Intelligence We are branched into a culture of movies and stuff where artificial intelligence is very present and associated with the idea of robots, but also systems capable to observe the environment and to react. But this is not what we should really think of, not robots as we are intended to think, but more simple systems. The first definition of artificial intelligence came into 60s: artificial intelligence is a technique of getting machines to work, act, or behave as a human. Then the question is why is AI relevant in medicine? There are some answers:
Today, AI in medicine can be used into several applications, like:
Supervised Learning #4: conclusions Now that we said everything to now about supervised learning algorithms, we can resume everything with these take-home messages:
infer the properties of this probability density without the help of a supervisor or a teacher providing correct answers or degree-of-error for each observation. An important thing is that, given a dataset, sometimes we have to see clearly if there is an initial pattern by view, in order to make some initial considerations: that’s why we can make an exploratory analysis before we assure that we can set up a protocol to learn from data. We can use a large quantity of tools, like PCA for dimensionality reduction. There are batch of different methods of different complexity. Among these we can define association rules , that represent the basic method, with simple approaches, very common into commercial databases. Having a set of observations we have to find the joint values of the most frequent variables in the dataset: we are
And, to have a tractable problem, both the goals of the analysis and the generality of the data to which is applied must be greatly simplified. So, at a certain point we have to simplify our problem Unsupervised Learning #2: clustering Creation Processing Analysis Preservati on Access Reuse
Another method for unsupervised learning is the so-called clustering : its goal is to find similarities between objects, represented by our data or observations. These methods, in general, are called partitional clustering , because they partition space into regions that we can use to assign new data. It works such that pairwise dissimilarities between those assigned to the same clusters tend to be smaller in than those in different clusters. We can set up several algorithms to make clustering, that are divided into three main groups. Combinatorial algorithms work on data without looking on underlying probability models, assigning each observation to a group of clusters, labeling the observation with an integer. A number of clusters K has to be set as a parameter of the problem, one of each is encoded by an integer. The goal for these algorithms is to find the optimal encoder, where the key point is the optimality. The idea is such that it satisfies the minimization of a measure over the observation pairs and their similarity degree. A simple example can be found in the computation of the total point scatter : this is a quantity constant, given the data.
∑ i = 1 N ∑ i'^ = 1 N
∑ k = 1 K ( ∑ C ( i'^ )= k di i' + (^) ∑ C ( i )^ ≠k
)
W and B quantities are the within-point-scatter and the between-point-scatter. We can set up a mathematical loss function for W and attempt to minimize it, corresponding to maximize B. Such optimization by complete enumeration is feasible only for very small datasets, then the number of distinct assignments becomes quickly very big. Another group of algorithms is called mixture modelling , where we can set up protocols that estimate the probability density functions with Bayes methods. Then we can cite mode seekers , estimating distinct modes of probability density functions without parametric approaches. Unsupervised Learning #3: K-Means K-means algorithm is an iterative descent clustering method in which variables must be quantitative and their space endows with Euclidean distance. This tool uses a few prototypes, Euclidean distance as similarity parameter and the number of cluster K a-priori fixed. The value of K is chosen by making an exploratory analysis or by advice of the expert following the project. Also, if there is some kind of prior knowledge, this doesn’t mean that a problem of UL becomes a problem of SL. Basically the algorithm works in a way like this:
use AI to solve all complex tasks, and this can be improved only if experts and programmers/analysts are communicating the right way. From our side, what we can do to make our best is to keep in mind the concepts of interpretability (are these models understandable for experts?), reproducibility (comparable results) and Human-Centered AI (because we are producing models designed for human beings). Problems to deal with During the first phases of working with data in ML, we can encounter several problems. One of the greatest in this field is data scarcity****. Sometimes projects are founded to grounded data, and we must pay for this. But there are a lot of possibilities by the way, like Open AI, API Scraping (useful to extract textual info in websites), or the way more common in medicine context, that is Data collected from scratch. This last one can be considered as the ideal situation, but today what happens is that we are dealing with large scale data, often and mistakenly called as big data. Our model must be described by using X and Y, so we need n samples in p variables, that are called measures or features. We often assume that p is a way greater than n (and this, mathematically speaking, could be a problem). But we do not obtain always data collected as X and labels collected as Y: we need to make a pre-processing first. This is an example of poor quality of data, but the quality is not always reflected on this. We can find some reasons:
Once concluded all data preparation, we can finally define a model. In medicine we often encounter multivariate models but also models with latent variables representing all the hidden phenomena involving some measures. For models like these we may not be able to measure all variables, but we can obtain better results by interdisciplinarity. But back to the model formulation, we got the X representing our input data and Y representing our labels. The goal is to find the f that better approximates Y from X. We can define two main common situations: when Y is nominal we can define a classification problem, that can be binary or multivariate. Then there is regression , in which we must approximate a curve. Moving towards medicine, the classification problem is often used in diagnosis, in particular binary one can represent healthy and sick subjects. We can also consider a multiclass problem, for example in genomic analysis or in disease staging, or also in differential diagnosis. The keyword used in problems like this is the “one-hot-vector”: this is a way to represent nominal labels by using a binary code. For example, if we have green, red and blue as labels, we can set respectively 100, 010 and 001. But why can’t we use simply 0, 1 and 2? We can, obviously, and this is called “integer encoding”, but integer values have a natural ordered relationship between each other, and some ML algorithms can understand and harness this relationship: if it is reflected also on our variables, it can be used, but this is not the case of red, green, and blue. And if we got more and more labels to make a classification, if I use integers ML algorithms can muddle and make an unwanted regression. Machine learning algorithms are used also in prognosis, but this is a more complex approach, because our method must incorporate time (because matrices are changing, both for regression and classification). In any case, the goal is the same: compute the best function. Machine learning is full of methods: basically, there are few that are like decision trees belonging to a specific problem, but others, like support vector machine (see later), belonging to all. This time, we consider deeply two methods: least squares and support vector machine. Least Square Method The least squares method can be considered in both problems. Starting from regression, we have data points in x and y. The goal is to find a function that best approximates y depending on x. The distance between the real y and the predicted y is near to 0. There are different functions doing the job, but we must identify the one that is the simplest possible. The easiest case is to use a model of linear function and then set parameters to best approximate data: we make a linear approximation. By design, the model of a linear function is
the loss function, but we commonly use distance or square loss. There are also other functions that are more used in classification problem. But in regression, we can set an example of algorithm: it consists of taking all the errors for data point and then compute m and b to obtain a minimized error. In formula we have that:
m ,b ∑ i ( f^ ( xi )−^ yi ) 2
m ,b ∑ i
2 This reflects on these expressions for m and b, having n samples:
n (^) ∑ i xi yi −∑ i yi ∑ i
n (^) ∑ i
2
(∑ i
)
∑ i yi − m ∑ i
√(^ TP + FP )^ (^ TP + FN )^ (^ TN + FP )^ (^ TN + FN ) Another method used in assessment is the representation of the receiver operating characteristic curve , better known as ROC curve , a graph showing the performance of a classification model at all classification thresholds. This curve plots two parameters: one is the true positive rate, or sensitivity , as we know it and the other is the false positive rate , corresponding to 1-specificity as we know it. It plots these values at different classification thresholds. Lowering the classification threshold, more items are classified as positive, thus increasing both false positives and true positives. This figure represents a typical ROC curve, where the area under the curve is a real parameter of the accuracy of the model. We can say that: AUC value Model
AUC=1 Perfection Regularization methods: an introduction When we introduced the problem of supervised learning, we also introduced the notions of underfitting and overfitting, saying that when we search for a model for our data, we need it simple, but not the simplest one. I can consider errors, counting and minimizing them, but without deleting them at all. The problem of overfitting, recurrent in medicine AI, comes when training has a 100% match, with a lowering assessing to the test set. The best we can do is to balance the outcome of training and testing sets. The opposite problem is underfitting: we can see that, for example in a LIGO experiment, that there is a trend but with a function that does not capture some other things. In the underfitting case, the model does not care about the data, or better, data does not contain enough information, or the training set is not big enough. In this case I can reduce model complexity or increase training size. The decision depends on what I’m working on, we must ask ourselves if the training size increment increases costs. Between the solutions we can apply, the most used are falling into regularization methods. These are a very wide class of methods dividing the problem in two parts: one referring to the fitting, making the comparison between y and f(x), and the other referring to the regularization, dependent only on the function f(x) we obtained. It can be described with this formula:
f ( L^ ( f^ (^ x^ )^ ,^ y^ )+^ λR^ ( f^ (^ x^ )^ ) ) The part referring to the fitting uses the loss function that search for the function f(x) as we saw on the
parameter or penalty. By making an example, the loss function can find our linear model, but we need it not so much vertical, and that’s where the regularization works. Of course, we must minimize this expression. So, having x and y, we can find our best f(x) approximating y, with the perfect solution passing through all data, but then we are given a test set that does not satisfies the similar conditions made up on the training part, with different errors; that’s why we need regularization. Now the question is how to choose the parameter lambda. Considering, for example, a classification problem:
But how this can be made in practice? There’s not so much to do rather than split our set. We make our first split by making learning and testing sets. Our test set is the benchmark, and that’s why we leave it separate from the rest. We start working into the learning set, splitting in two parts that are called training set and validation set. Each time we try a different lambda parameter setting a range of values. Then we validate the function getting an error. We can try different lambdas by making different chunks, then we are happy with that lambda minimizing the average error. This problem can be represented like this:
∑ i
∑ i
∑ i
∑ i
Sometimes regularization is composed by more than just one term, but the idea remains the same, regardless of the complexity of the model. This is what is done on cross-validation , meaning that we learn functions by repeating the process with more validation parts. At the end of the story, this is what we can do in practice in four passages:
feature space, so that data points can be categorized, even when data are not otherwise linearly separable. This can be considered as a regularized method basing also on the function: min (^) ∑ i = 1 n V (^) ( f (^) ( xi ) , y (^) )+ λ || f || k 2 The loss function here represented is called hinge loss : it consists of having no penalties when our data are correctly classified; in the opposite case, we set a higher loss, basing on how the error is great (mathematically speaking, the more the distance from the boundary increase (setting into the wrong area),
T
β (^) 0 ,β ∑ i = 1 n [ 1 −^ yi f^ (^ xi )^ ]+^
|| β || 2 Kernel Methods The last family of methods is the one called kernel methods. We’d like to solve linear methods, but what happens when our input space is complex? Kernel methods give us the answer by transferring the problem into the feature space, that means we are working into different dimensions and defining linear problems in these terms. We can use several functions to make this transfer, like the gaussian kernel or RDF. Other – not into quiz!! These are not the unique methods used. In fact, we can also consider k nearest neighbors that is an algorithm based on data point’s closeness. We keep a training group of classifications, and we consider the new data points classified on that (most frequent) group belonging to the k points next to him. It does not always work well because of the position of the new data, but this can be easily solved by choosing the right k, considering that it can’t be too small (because noise can affect the classification) neither too big (because unbalance can affect the classification). Another method used is the one called random forest : with the assumption that we know about the construction of a classification tree, this method grows many classification trees, each one affecting the general error rate basing on the correlation between couples of trees and the strength of each tree. The construction of that forest is also based on the training we make. To classify a new object, we put the input down every tree, each one giving a classification (or “voting” for the class) and then the object is classified into the most voted group. Feature Selection in Machine Learning In lots of machine learning problems, we often interface with large datasets having a particularly large whole of features, often regarding redundant and noisy information. So that’s why we need feature selection : this is an operation primarily focused on removing non-informative or redundant predictors from the model. This is
an advantageous process, having an impact on the supervised learning problem and making the overall learning process cheaper by a computational point of view, but it also reduces the complexity of a model making it easier to interpret, improves the accuracy of the model when right subsets are chosen and reduces overfitting. This process is important, especially when dealing with medical data: a feature can be a geometric property into a medical image, a specific gene to describe the development of a tumor, or some biomarkers to identify into molecular data. There are lots of examples for variable selection: these are very relevant despite they probably belong to the deep learning class (see later). Into these examples there aren’t the already saw methods regarding dimensionality reduction , such as PCA, because these methods simplify the problem by projecting the whole set of features into just 2 or 3 new features, without removing the old ones. In feature selection, instead, we remove all the features we are not interested in. These examples can be divided in three families of methods: filter, wrapper, and embedded methods. Filter methods evaluate the relevance of the variables outside of the predictive models and subsequently model only the predictors that pass some criterion. So, into a supervised learning problem, we check every single feature at a time, subjecting them to a filter, that classifies this feature as relevant or not, basing on some criteria we defined. By a mathematical point of view, we can say that:
¿
ANOVA, t-test and so on, obtaining a p value for each. Then we can rank our features basing on this p-value, then discarding all the variables having a p-value greater than a threshold we decide. Sometimes we need also to make corrections Bonferroni -like and to consider correlation, cause filter methods does not take this automatically, and it is useful when an enrichment analysis (add features) is necessary. Filter methods are simple and fast, scaling well to high dimensional data and being independent of the classifier but this is, generally, a univariate or low-variate method. (*2). Wrapper methods, instead, evaluate multiple models using procedures that add or remove variables to find the optimal combination that maximizes model performance. It generates the subset by what we can obtain from the learning algorithm, with an iterative process. The clearest example is the recursive feature elimination in support vector machine, known as SVM-RFE. We start with our original set made by p
of the model (see last chapters). We rank them and we discard the worst 10, and then we go back to our sub- featured matrix, and we restart the process. In medicine, we use these methods especially when we analyze medical images, because are requiring lots of data. These methods select a near perfect subset and the error rate is less as compared to other methods. But there are also cons: these methods are computationally very intensive and are intended for the learning machine on which it has been tested; therefore, there is a high risk of overfitting than filter techniques. Then, embedded methods are called so because there are some model containing a built-in feature selection, meaning that the model will only include variables that help maximize accuracy. So, having a set of features we directly feed them to the learning algorithm including both training (with performance analysis and optimization) and feature selection. Their functioning is based on a specific regularization to enforce sparsity, meaning that the more the function is regular, the less are the feature selected. Depending on the loss and on the algorithm, we can define different models, but we can define some examples into the least square method. We start considering, as a premise, the already seen RLS , in which add a simple constraint to the OLS to have regularization, and this is written like:
β
2
In this regularization we do not cancel features, because there are no coefficients set to 0 that, from a mathematical point of view, cancel some X’s columns. So, what if we decide to make it possible by taking
SVM
Data\Labels Continuous Categorical Continuous Pearson’s Correlation LDA
Deep Learning Deep Learning, in a sense, it has become a synonym for AI, also because it is used in several and popular applications: for example, the most popular systems available in free trial in Open AI, like chat GPT (a chatbot capable of understanding a question and formulating an answering text) or Dall-E (image generator based on the description you give), but is also widely used in medical applications, such as medical imaging. In this section will be discussed Deep Learning’s functioning and some of its limitations (such as the computational power, considering that in DL methods we need more and more data than in ML methods and that we have to choose also between some hyperparameters). We already know that DL is a subset of ML that is a subset of AI. In this case we consider the same problems as we did in ML, so classification and regression, but with a different methodological approach, considering that in this case we are not searching for a model able to solve the problem, but we are searching for the best parameters for some existing architectures, that are called deep neural networks. What is a neural network? The concept of neural network is not new by a theoretical point of view, but the news is that we are finally capable of computing them (even if is not so easy and quick). In networks we can define a simple structure, in which input elements (variables) are connected to each output element (label): connections are based on parameters that has to be learned by minimizing some functions. Input and output elements, in DL slang, are called layers. It’s easy to explain why these networks are called neural: in fact, the theoretical principle is similar to what happens in neurons, where different stimuli are arriving at the same time from neighborhood’s neurons, and its response can be represented by an activation function (that is called action potential ), firing the response basing on the weighted sum of the stimuli arriving. So, we can follow this neuron parallel to define the architecture of our network, based on three operations: weight, sum up and activate. This concept is not new, and it has been formulated in 1958 by Mr. Rosenblatt , when he defined the perceptron , the simplest neural network ever. Perceptron takes into account all the signals coming in input with their weights and a bias , going into the activation function. That is, in formula:
( w 0 +∑ i = 1 m
) Now, if we consider a matrix, each element undergoes through this transformation. We can optimize for all data points we have. This schema is then considered for all data points, obtaining just one element of y. In a sense, we got this: ^ yi = φ ( Xi^ T^ W + w 0 ) So, there are different parameters for a different element of Y and that’s why we use several parameters in NN. The classical examples functioning with perceptron are the simplest linear problems, like the OR and the AND functions. These are both used in disease classification. Consider a bidimensional output, where 0 correspond to normal and 1 not. When diagnosis requires at least one variable equal to 1, we need a OR function, and when diagnosis requires both elements equal to 1 we need the AND one. Here we got all the activation functions f(z) that are considered:
{
{
What are DEEP neural networks All it’s easy and linear, until we encounter more complex problems like the XOR function. A linear model is not able to solve this, but we can consider it as a combination of AND with OR: better saying, we verify if x_1 and not x_2 gives TRUEORnot x_1 and x_2 gives TRUE. By the architectural point of view, we have added an intermediate layer to the classical perceptron and obtained a multi-layered perceptron. This intermediate step is called hidden layer, and when we got hidden layers we got deep neural networks, where each of the edges represents manipulation of the previous layer. To obtain a more complex model, we have just to add more and more hidden layers. In a practical way we can use some already trained networks or different architectures belonging to the most popular deep learning methods, such as geometric deep learning and convolutional neural networks. In deep learning methods, we can find the optimal representation and the best model using raw data: we don’t need feature extraction as we needed in ML and we just skip the part of ordinary pre-processing. Shallow vs Deep Another example of neural network is the one referring to shallow neural networks: this is a family of deep learning methods used when the dataset is too small for deep neural networks as we knew. These networks are composed by just 1 or 2 hidden layers, but with a large number of neurons per layer comparing to input and output. There is a theorem (Cybenko, Hornik, Stinchombe, White, Allan Pinkus; 1989-1999) saying that a neural network with one single layer is a universal approximator , i.e., it can represent any continuous
problems, and in practice just one layer is enough to solve problems but having an exponential number of neurons to get a prediction error close to 0. We still have a high number of parameters to learn, so that’s why we more often fall into usual deep neural networks with more hidden layers. Learning process and hyperparameters From a mathematical viewpoint, we have a series of different layers transforming the input according to functions and weights. Choose the right architecture it’s easy, but we still have to learn these weights for each transformation. We can use an example in imaging: we often use pyramidal approaches to have information at different scales, so we can consider each layer of a DNN as some parts of the image, extracting information at different scales. So, let’s see how to train our deep neural network. In formula, we can consider this: h 1 = φ (^) ( w 0,1 + X T W (^) 1 ) → h 2 = φ (^) ( w 0,2 + h 1 T W (^) 2 ) → … → hH = φ (^) ( w 0 , H + hH − 1 T W (^) H ) → ^ y = φ ( w 0 , H + 1 + hH T W (^) H + 1 ) All the W are the parameters to learn from our data, but there is also the problem of the activation function. At the end, we set all the neurons and the function deals with an optimization problem. The selection of the right activation function is important because it introduces non linearities in the model. There are lots of examples, but the most used are the logistic function and the ReLU. Once we have chosen the activation function, we end up solving the problem by learning the parameters, made by using a loss function and optimizing according to all data points. In practice, we use a random start at time 0, and we update at each timestamp, or epoch , iteratively. This process is regulated by another
set a priori so easily: