Machine Learning (Coursera): Part 2/2

167 flashcards · Computer Science · by charlie42

  1. The recommended approach to solving machine learning problems (3 steps)

    Quick and dirty model Print learning curves to see how to improve (more examples, more features, etc.) Examine errors in CV set to see if there is a pattern

  2. What's error analysis in machine learning?

    Examining errors in CV set to see if there is a pattern, to improve performance of the model

  3. What does precision (machine learning metric) measure?

    How many, out of predicted positive cases, are actually positive

  4. Formula for precision (machine learning metric)

    True positive / (True positive + False positive)

  5. What does recall (machine learning metric) measure?

    Out of all cases of actual positives, how many were predicted as positive

  6. Formula for recall (machine learning metric)

    True positive / (True positive + False negative)

  7. What class to we usually call positive?

    A more rare one

  8. What happens to precision and recall if we choose to change the standard threshold of logistic regression of 0.5 to 0.7?

    Precision will increase Recall will decrease

  9. Why precision is not 0 when the model always predicts y=1

    Because we have some actual y=1 values that were predicted correctly

  10. Why do we need a single metric, that puts together precision and recall?

    To speed up decision making process when choosing the best classifier. Considering if the ratio is good manually every time is time consuming.

  11. Why the average of precision and recall is not a good metric?

    It can give high values when recall is 1 but precision is almost 0 (Model predicts all values as y=1)

  12. Common metric (and it's formula) that combines precision and recall in a way that it's high when both are high, and low when one is low

  13. When is the F1 score is 0?

    When either precision or recall is 0

  14. When is the F1 score is 1 (perfect)?

    When both precision and recall are 1

  15. Two rules for when adding more data will help to improve performance

    An expert could predict y given features X The model is complex enough to have low bias

  16. What does the cost function for a single training example looks like for the SVM when y=1?

  17. What does the cost function for a single training example looks like for the SVM when y=0?

  18. Why can we get rid of the 1/m constant when going from the cost function of logistic regression to the cost function of SVM?

    When minimizing a function, multiplying it by a constant doesn't change the resulting value

  19. When minimizing these two equations, what C should be equal to to obtain the same values?

    C = 1/lambda

  20. Cost function of SVM

  21. Why do we add 1/2 before the regularization term in cost function

    To not have 2 in front of it after we take the partial derivative

  22. What's the difference in the hypothesis between logistic regression and SVM?

    Logistic regression outputs the probability, SVM outputs a discrete value (1 or 0)

  23. What does the plot of the cost function of logistic regression over z for one training example looks like when y=1?

  24. What does the plot of the cost function of logistic regression over z for one training example looks like when y=0?

  25. Why does the plot of the cost function of logistic regression over z when y=1 look like this?

    For the cost function to be low, h(x) = g(z) should be 1. g(z) is 1 when z is large.

  26. What z is equals to in logistic regression for a single example?

    z = θTx

  27. Three differences between SVM and logistic regression cost functions?

    In SVM we don't divide the sum of individual cost functions by m In SVM the lambda constant is moved to the other term The cost function for each case (y=1 and y=0) is changes

  28. The difference between SVM and logistic regression hypothesis functions?

    The SVM hypothesis function outputs 1 or 0, not a probability

  29. When is the hypothesis function of the SVM is 1?

    When θTx >> 0

  30. Why there is no - (minus) sign before each term (for y=1 and y=0) in the SVM cost function, as oppose to the logistic regression cost function?

    The - signs just make the logistic regression cost functions for y=0 and y=1 look the way they do In the SVM cost function the shape is fully defined by the cost1 and cost2 terms

  31. Term for multiplying to vectors of the same length?

    Vector inner product

  32. How can we represent this vector visually

  33. What's ||u|| and how to calculate it?

    Norm of a vector u = euclidian length of the vector u

  34. Hypothesis function for SVMs

  35. How to calculate the vector inner product of u and v using the projection of v onto u?

  36. Two ways to calculate inner vector product of u and v

  37. When is the projection of v onto u is negative?

    When the angle between v and u is more than 90o

  38. When is the vector inner product of v and u negative? Why?

    When the projection of v onto u is negative => When the angle between v and u is more than 90o

  39. What is a kernel function in SVMs?

    Similarity function between a training example and a landmark

  40. Gaussian similarity function formula

  41. Range of similarity function values

    (0, 1)

  42. What does the gaussian similarity function with a single landmark look like on a plot, when we have two features, with these two values of sigma

  43. What does the new hypothesis function for SVM looks like with three landmarks

  44. What could be the values of theta if we want to predict y=1 when the training example is close to landmarks l1 and l2, but far from l3? Why?

    [-0.5, 1, 1, 0] If x is close to l1 or l2, but far from l3, the value of the equation will be 1 If x is close to l3, but far from l1 and l2, the value of the equation will be -0.5

  45. Where the landmarks are usually located for non-linear SVM kernels?

    At the location of each training example

  46. How is one training example represented in SVMs with kernels?

    List of similarities of this training example x to all landmarks (instead of list of values at each coordinate x1, x2, etc.) One of the values will be equal to 1, because one of the landmarks is located exactly at the location of this training example

  47. Vectorized hypothesis of SVMs with kernels

  48. Difference between the cost function of the SVM with linear and non-linear kernels Write the cost function of the SVM with non-linear kernel (with vectorized hypothesis function and regularization)

    In hypothesis function, the training example is replaced with it's representation with the values of it's similarity with each landmark

  49. Why we shouldn't use kernels with other algorithms like logistic regression?

    SVMs are optimized for fast computations with kernels, logistic regression would be very slow with n=m

  50. To decrease bias (increase variance) in an SVM with the gaussian kernel, what should we do with σ?

    We should reduce it, it will make the similarity function vary less smoothly

  51. When do we want to use the linear kernel (no kernel) or logistic regression over a non-linear SVM? Why? (2 cases)

    When we n >= m. If we try to fit a complex non-linear function there is a risk of overfitting. When m is very large. Gaussian kernel can struggle computationally. Can try adding features manually and running logistic regression or no kernel SVM

  52. Why do we need to use feature scaling when using the SVMs with gaussian kernel?

    The norm (the numerator in the similarity function) is decomposed by dimensions (features). If some features take large value ranges, the smaller ranged values won't change the similarity value much.

  53. Two advantages of SVMs over neural networks

    Often faster Convex cost function - no local optima (not really a problem in practice with NNs)

  54. 3 steps of the k-means algorithm

    Randomly initialize k centroids Repeat { Assign each point to the nearest centroid Re-calculate centroids }

  55. k-means: notation for: Centroids Number of clusters Index of a centroid closest to x(i)

    μ1, μ2, ... μK K c(i)

  56. k-means: how to assign each point to the nearest centroid (pseudocode)

  57. k-means: how to calculate the closest centroid to a point

  58. k-means: how to recalculate centroids (pseudocode)

  59. k-means: how to calculate the average of points

    Sum up the feature vectors, divide the resulting vector by the number of vectors

  60. The optimization objective of k-means (equation)

  61. With regards to what the cost function is minimized during the first step of the inner loop of k-means (assigning each point to a cluster)? Which values are fixed?

    c(i) We fix the location of centroids (μK), and minimize the distance between the points and their centroids by assigning points to their closest centroid

  62. With regards to what the cost function is minimized during the second step of the inner loop of k-means (recalculating the centroids)? Which values are fixed?

    μi We fix what centroid a point is assigned to (c(i)), and minimize the distance between the point and their centroid by moving the centroid

  63. Cost function of k-means in words

    Average distance between each point and the cluster it belongs to

  64. Where are the initial cluster centroids usually initialized?

    Exactly at the location of K random training example

  65. What the cost function of k-means is called?

    Distortion function

  66. Write the algorithm for avoiding local optima for k-means. When does it have more chance to give good results?

    About 100 times: Randomly initialize centroids Run k-means, get c(i...m) and m1...K Compute the final cost function (J) Choose c(i...m) and m1...K values that give the smallest J It gives better results if K is low (2-10). When discovering more clusters, different random initializations are unlikely to change the value of J much

  67. What's the elbow method and how is it used for k-means?

    It's used to choose the number of clusters.

  68. Why the elbow method is not used often to choose the number of clusters in k-means?

    In real life, the cost function curve doesn't have a clear "elbow"

  69. k-means: two explanations for k=5 having a lower final cost function value than k=3

    There are 3 natural clusters in the data The k=5 run fell into a local minimum, try to rerun it with another random centroid initialization

  70. k-means: what's an alternative to the elbow method for choosing k?

    Think why you're running k-means, and which number of clusters serves that purpose better

  71. Suppose we apply dimensionality reduction to a dataset of m examples {x(1), x(2), …, x(m)}, where x(i) ∈ Rn. As a result of this, we will get:

    A lower dimensional dataset {z(1), z(2), …, z(m)} of m examples where z(i) ∈ Rk, and k ≤ n

  72. Two common use-cases for dimensionality reduction

    Data compression (k ≤ n) Data visualization (k ≤ n, k = 2 or 3)

  73. In words, what's the goal of 2D to 1D PCA?

    To find a direction (a vector u ∈ Rn) onto which to project all data points so as to minimize the projection error

  74. In words, what's the goal of PCA?

    To find k vectors u(1), u(2),..., u(k) onto which to project all data points so as to minimize the projection error

  75. 2 differences between linear regression and PCA?

    In linear regression we minimize the difference in z. In PCA we minimize projection error (shortest distance between the point and the line) In linear regression there is a distinct variable y that we want to predict. In PCA we treat all variables equally.

  76. What x(i) ∈ ℝ2 becomes after dimensionality reduction?

    z(i) ∈ ℝ (Now we only need one number to represent the data points)

  77. Notation for covarience matrix

    Σ

  78. Two functions in octave to compute eigenvectors

    eig svd (singular value decomposition)

  79. What does covariance matrix look like for two and three variables?

  80. Covariance matrix formula when mean = 0

  81. What does this part of covariance matrix formula represent?

    "Instantaneous" covariance matrix, for one training example

  82. Dimensions of the covariance matrix (explain why)

  83. Which eigenvector is used for the PCA algorithm? What does it represent?

    U Each column will be the u vector onto which the data will be projected. We take the first k vectors to which we want to reduce the dimensions

  84. Dimensions of the U matrix

    n x n

  85. PCA: How to get new training examples, in reduced dimensions?

    (Ureduced)T * X Ureduced is U with only k first columns

  86. What do we need to do with the data before running the PCA algorithm?

    Mean normalization (mandatory) Feature scaling (highly recommended)

  87. Full PCA algorithm

  88. Difference between the X matrix for PCA and for Linear regression

    We don't add the x0 = 1 column for PCA

  89. Explain (PCA)

    To calculate column j of z we need to project all columns of x to the new j vector

  90. What approximate reconstruction of the original data from the result of PCA looks like on a graph (2D)?

  91. Formula to calculate approximate reconstruction of the original data after the PCA

  92. What PCA wants to minimize (+ formula)

    Average squared projection error

  93. Formula for total variation in the data and what it represents

    Average length of between each data point and the origin

  94. Formula to calculate how much varience is retained by PCA

    (99% varience is retained)

  95. Alternative (faster) way to calculate how much varience in retained by PCA

    where

  96. What does the matrix S look like

  97. Visualize what does this formula calculates on the matrix S

    For k=3,

  98. Common acceptable % of varience retained (PCA)

    95-99%

  99. Describe the procedure regarding PCA and training and test sets

    Learn the PCA mapping on training set (Ureduced, parameters for mean normalization and feature scaling) Apply the parameters on the test set.

  100. 2 misuses of PCA

    to prevent overfitting not trying to run the algorithm without it first