Artificial Intelligence & Machine Learning, Zusammenfassungen von Künstliche Intelligenz

Toggle sidebar
bg1
3/13/2026
1
Fundamental Algorithms
Part II
Dr. Berke Gür
Artificial Intelligence & Machine Learning
Dr. Berke Gür
3/13/2026
1
Chapter Overview
•Fundamental ML algorithms are introduced
–Linear regression
–Logistic regression
–Decision trees
–Support vector machines (SVM)
–kth nearest neighbor
•Using these algorithms, one can perform both regression &
classification
Artificial Intelligence & Machine Learning
Dr. Berke Gür
3/13/2026
2
1
2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Unvollständige Textvorschau

Nur auf Docsity: Lade Artificial Intelligence & Machine Learning und mehr Zusammenfassungen als PDF für Künstliche Intelligenz herunter!

1

Fundamental Algorithms

Part II

Dr. Berke Gür Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 1

Chapter Overview

  • Fundamental ML algorithms are introduced
    • Linear regression
    • Logistic regression
    • Decision trees
    • Support vector machines (SVM)
    • kth nearest neighbor
  • Using these algorithms, one can perform both regression & classification Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 2 1

2

Decision Trees

  • A decision tree is an non-cyclic graph that can be used to make decisions
  • A specific feature ( j) of the feature vector is examined in each branching node of the graph
  • If the value of the feature is below a specific threshold, then the left branch is followed (otherwise, the right branch is followed)
  • As the leaf node is reached, the decision is made about the class to which the example belongs
  • A decision tree can be learned from data Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 3

Typical Decision Tree

Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 4 3

4

Solution to the Decision Tree Problem

  • In this form, the ID3 problem looks very similar to the logistic regression problem
  • The logistic regression learning algorithm builds a parametric model (fw, b) by finding an optimal solution to the optimization criterion
  • In contrast, the ID3 algorithm optimizes the criterion approximately by constructing a nonparametric model fID3(x) = Pr(y = 1|x) Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 7

Training the Decision Tree

  • Let (S) denote a set of labeled examples
  • In the beginning, the decision tree only has a start node that contains all examples S = {(xi, yi)}Ni = 1
  • Start with a constant ID3 model ( f SID3) defined as
    • |S| denotes the size (no of samples) of the dataset
  • The prediction given by the above model [ f SID3(x)] would be the same for any input (x) Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 8 ID 1 1 | | N S i i f y S (^) 

7

5

Training the Decision Tree

  • Then search through all features j = 1,... , D and all thresholds (t) & split the set (S) into 2 subsets - S−^ = {(x, y) | (x, y) ∈ S, x(^ j)^ < t} - S+^ = {(x, y) | (x, y) ∈ S, x(^ j)^ ≥ t}
  • The 2 new subsets would go to two new leaf nodes
  • Evaluate for all possible pairs ( j, t) how good is the split with pieces (S−) and (S+)
  • Pick the best such values ( j, t) & split (S) into (S+) and (S−) to form 2 new leaf nodes
  • Continue recursively on (S+) and (S−)
  • Quit if no split produces a model that’s sufficiently better than the current one Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 9

Training the Decision Tree

Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 10 9

7

Training the Decision Tree

  • The algorithm stops at a leaf node in any of the below situations:
    • All examples in the leaf node are classified correctly by the one-piece model
    • An attribute to split upon cannot be found
    • The split reduces the entropy less than some (ε) value (the value for which is found experimentally)
    • The tree reaches some maximum depth (d, also found experimentally)
    • Experimentally finding these parameters corresponds to hyperparameter tuning Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 13

Ex: ID3 Decision Tree for «Halısaha» Dataset

  • A dataset for playing football («halısaha») is given in the table on the next slide
  • Construct an ID3 decision tree using entropy and information gain as the attribute selection measures
  • The information gain metric is defined as
    • H(∙): is entropy
    • x(j): represents the jth^ feature
    • a: is a specific attribute of that feature Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 14 ( ) ( ) ( ) Information [ ] [ , ] Gain( , ) j j x j^ a H x^ H x^ a     ^    13

8

Ex: ID3 Decision Tree for «Halısaha» Dataset

Day Outlook Temperature Humidity Wind Play? D1 Sunny Hot High Weak No D2 Sunny Hot High Strong No D3 Overcast Hot High Weak Yes D4 Rainy Mild High Weak Yes D5 Rainy Cool Normal Weak Yes D6 Rainy Cool Normal Strong No D7 Overcast Cool Normal Strong Yes D8 Sunny Mild High Weak No D9 Sunny Cool Normal Weak Yes D10 Rainy Mild Normal Weak Yes D11 Sunny Mild Normal Strong Yes D12 Overcast Mild High Strong Yes D13 Overcast Hot Normal Weak Yes Artificial Intelligence & Machine LearningD14 Rainy Mild High Strong No Dr. Berke Gür 3/13/ 15

Support Vector Machine

  • Support vector machine (SVM) is a popular classification algorithm
  • Computes an N-dimensional line (hyperplane) separating the classes
  • The boundary separating the examples of different classes is called the decision boundary
  • The form of the decision boundary determines the accuracy of the model
  • The accuracy of a model is the ratio of examples whose labels are predicted correctly Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 16 15

10

Support Vector Machine

  • Margin is the distance between the closest examples of two classes as defined by the decision boundary
  • A large margin contributes to a better generalization (how well the model will classify new examples in the future)
  • To maximize the margin, the Euclidean norm of (w) needs to be minimized Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 19 ( ) 2 1 [^ ] D (^) j

w   j  w

Support Vector Machine

  • However, for (quadratic) programming purposes it is preferred to minimize ½||w||^2
  • Quadratic programming is a nonlinear programming method for solving optimization problems that involves quadratic functions - One seeks to optimize (minimize or maximize) a multivariate quadratic function of the form (½·xT·Q·x + cTx) subject to linear constraints of the form (A·x  b)
  • Optimization problem for SVM
    • Minimize ½||w||^2 such that yi · (w·xi − b) − 1 ≥ 0, for i = 1, …, N Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 20 19

11

Support Vector Machine

  • 2 problems regarding SVM needs to be addressed - A linear hyperplane might not always be the most optimum solution - It may not be possible to find a hyperplane separating the data Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 21

Shortcomings of Linear Hyperplanes

  • This version of SVM we introduced builds a linear model (the decision boundary is a straight line)
  • Linear models of 2 or higher dimensions have decision boundaries in the form of a linear plane or a linear hyperplane
  • SVM can also incorporate kernels that can make the decision boundary arbitrarily non-linear - The data can be transformed to a new space that will make it linearly separable - Using a function to implicitly transform the original space into a higher dimensional space during the cost function optimization is called the kernel trick Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 22 21

13

Non-Linear Hyperplanes

  • Recall the optimization problem for SVM in the form of
    • Minimize ½||w||^2 such that yi · (w·xi − b) − 1 ≥, for i = 1, …, N
  • This optimization problem can be recast using Lagrange multipliers as
    • where αi are called Lagrange multipliers
  • In this form, the optimization problem becomes a convex quadratic optimization problem which can efficiently be solved using quadratic programming
  • Notice the dot product (xi • xk) is the only part of the optimization function where the feature vectors appear Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 25 1 1 1 1 1 ,..., 1 max ( ) subject to 0 and 0, 1, 2,..., 2 N N N N N i i^ i k yi^ i^ i^ k^ yk^ k^ i i^ yi^ i i^ N  

  ^ ^      x^ ^ x   ^ ^ 

Non-Linear Hyperplanes

  • Applying the transformation φ([q 1 , p 1 ]) = (q 12 , √2q 1 p 1 , p 12 ) & φ([q 2 , p 2 ]) = (q 22 , √2q 2 p 2 , p 22 ) followed by the dot product yields φ([q 1 , p 1 ]) • φ([q 2 , p 2 ]) = (q 12 q 22 + 2q 1 q 2 p 1 p 2 + p 12 p 22 )
  • Instead of this costly operation, we can take the square of the dot product between [q 1 , p 1 ] & [q 2 , p 2 ] to get the same result ([q 1 , p 1 ] • [q 2 , p 2 ])^2 = (q 12 q 22 + 2q 1 q 2 p 1 p 2 + p 12 p 22 )
  • This is an example of the kernel trick where the quadratic kernel in the form of k(xi, xk) = (xi • xk)^2 is utilized Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 26 25

14

Non-Linear Hyperplanes

  • The most widely used kernel is the Radial Basis Function (RBF) kernel
    • where the Euclidian distance between the features is given as
    • and where the hyperparameter (σ) can be tuned to get a smooth or curvy decision boundary in the original space Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 27 2 ( , ) exp (^2) 2 k   (^)    (^)        x x x x   ( ) ( ) 2 1 [^ ] D (^) j j

x  x   j x x

 

The Noisy Data Problem

  • In some cases, it could be impossible to perfectly separate the two groups of points
  • This could be caused by noise in the data, errors of labeling, or outliers
  • Outliers are examples very different from a «typical» example in the dataset
  • Another version of SVM can also incorporate a penalty hyperparameter for misclassification of training examples of specific classes
  • A hyperparameter is a property of a learning algorithm, usually (but not always) having a numerical value - That value influences the way the algorithm works - Those values aren’t learned by the algorithm itself from data - They have to be set by the data analyst before running the algorithm Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 28 27

16

k-Nearest Neighbor

  • k-Nearest Neighbors (kNN) is a non-parametric learning algorithm
  • Other learning algorithms allow discarding the training data after the model is built
  • kNN keeps all training examples in memory
  • Once a new & previously unseen example (x) comes in, the kNN algorithm finds (k) training examples closest to (x) & returns the - Majority label (classification) - Average label (regression) Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 31

k-Nearest Neighbor

  • The closeness of 2 examples is given by a distance function
    • Euclidean distance is frequently used in practice
    • Mahalanobis distance is also popular for random variables where (μ) represents the mean and (Σ) is the covaraince matrix Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 32 ( ) ( ) 2 1 [^ ] D (^) j j

x  x   j x x

  ( ) 1 ( ) d (^) M      x μ (^) x Σ x μx  31

17

k-Nearest Neighbor

  • Another popular choice of the distance function is the negative cosine similarity
  • Cosine similarity defined as is a measure of similarity of the directions of two vectors
  • If the angle between two vectors is 0° & the 2 vectors point to the same direction resulting in a cosine similarity of 1
  • If the vectors are orthogonal, the cosine similarity is 0
  • For vectors pointing in opposite direcƟons, the cosine similarity is −
  • To use cosine similarity as a distance metric one needs to mulƟply it by − Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 33

( ) ( ) 1 2 1 2^2 1 2 ( ) ( ) 1 1 ( , ) cos[ ( , )] D (^) j j j^ i^ k i k i k (^) D D j j j i^ j k x x s x x         (^)      

x x x x

k-Nearest Neighbor

  • Other popular distance metrics include Chebychev distance and Hamming distance
  • The choice of the distance metric & the value for (k) are the choices the analyst makes before running the algorithm (they are hyperparameters)
  • The distance metric could also be learned from data (as opposed to guessing it) Artificial Intelligence & Machine Learning Dr. Berke Gür 3/13/ 34 33