1. Home
  2. Explore
  3. Computer Science
  4. Machine Learning for Beginners

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Machine Learning for Beginners

  • 44Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Machine Learning Basics

What is the key difference between supervised and unsupervised learning?

44 questions

  1. 1

    What is the key difference between supervised and unsupervised learning?

    Model answer

    Supervised learning uses labeled data (input-output pairs) to train models for prediction, while unsupervised learning uses unlabeled data to find patterns or structure.

    Explanation

    Supervised learning requires labels for training, enabling direct comparison between predictions and true values; unsupervised learning discovers groups or features without predefined labels.

  2. 2

    Define machine learning and explain how it differs from explicit programming.

    Model answer

    Machine learning is a subdomain of computer science where algorithms learn from data without being explicitly programmed for every task; explicit programming requires the programmer to specify all rules.

    Explanation

    ML models extract patterns from data, allowing them to generalize to new inputs, unlike traditional programs where every decision is coded.

  3. 3

    What is the difference between AI, machine learning, and data science?

    Model answer

    AI is the broad field of enabling machines to perform human-like tasks; ML is a subset of AI that makes predictions from data; data science extracts insights and patterns from data often using ML.

    Explanation

    AI encompasses any technique mimicking human intelligence; ML specifically learns from data; data science applies statistical and computational methods to gain knowledge.

  4. 4

    What is reinforcement learning and how does it work?

    Model answer

    Reinforcement learning involves an agent learning in an interactive environment through rewards and penalties, encouraging desirable behaviors.

    Explanation

    The agent takes actions and receives feedback (reward/penalty), updating its strategy to maximize cumulative reward, similar to training a dog.

  5. 5

    Explain the difference between qualitative and quantitative features, and give an example of each.

    Model answer

    Qualitative features are categorical (e.g., gender) with no numeric order; quantitative features are numerical (e.g., length) and can be discrete or continuous.

    Explanation

    Qualitative data includes nominal (no order) and ordinal (inherent order) types; quantitative data is numeric and can be measured.

  6. 6

    What is one-hot encoding and when is it used?

    Model answer

    One-hot encoding converts categorical data into binary vectors where one element is 1 (indicating the category) and the rest are 0; used for nominal data without order.

    Explanation

    Computers handle numbers better than words; one-hot encoding creates a binary column for each category, allowing models to treat categories equally.

  7. 7

    What is the difference between nominal and ordinal data? Provide an example of each.

    Model answer

    Nominal data has no inherent order (e.g., nationality); ordinal data has a natural order (e.g., age groups like baby, toddler, teenager).

    Explanation

    Ordinal data can be mapped to numbers preserving order, while nominal data cannot be meaningfully ranked.

  8. 8

    Explain the difference between binary classification and multi-class classification.

    Model answer

    Binary classification predicts between two classes (e.g., hot dog or not hot dog); multi-class classification predicts among more than two classes (e.g., cat, dog, lizard).

    Explanation

    The number of output categories distinguishes them; binary has exactly two, multi-class has three or more.

  9. 9

    What is regression in supervised learning?

    Model answer

    Regression predicts a continuous numerical value (e.g., house price, temperature) based on input features, rather than discrete classes.

    Explanation

    Unlike classification, regression outputs a real number, aiming to be as close as possible to the true continuous value.

  10. 10

    Define feature vector, feature matrix, and target vector in the context of supervised learning.

    Model answer

    A feature vector is the set of features for one sample; the feature matrix X contains all feature vectors (rows) and columns are features; the target vector y contains the labels for all samples.

    Explanation

    X is of shape (n_samples, n_features), y is (n_samples,). These are the standard inputs for training supervised models.

  11. 11

    Why do we split data into training, validation, and test sets?

    Model answer

    To evaluate model generalization: training set fits the model, validation set tunes hyperparameters, test set gives final unbiased performance estimate.

    Explanation

    Using the same data for training and testing would overestimate performance. Validation helps avoid overfitting by monitoring unseen data during training.

  12. 12

    What is loss in machine learning?

    Model answer

    Loss is a numerical measure of the difference between predicted and actual values; it quantifies model error and is minimized during training.

    Explanation

    Common loss functions include L1 (absolute error), L2 (squared error), and binary cross-entropy; lower loss indicates better prediction accuracy.

  13. 13

    Explain L1 loss and L2 loss. How do they differ?

    Model answer

    L1 loss is the sum of absolute differences ∑∣yi−y^i∣\sum |y_i - \hat{y}_i|∑∣yi​−y^​i​∣, while L2 loss is the sum of squared differences ∑(yi−y^i)2\sum (y_i - \hat{y}_i)^2∑(yi​−y^​i​)2. L2 penalizes large errors more heavily.

    Explanation

    L1 is more robust to outliers; L2 is differentiable everywhere (useful for gradient-based optimization) and amplifies large errors.

  14. 14

    What is accuracy and how is it calculated?

    Model answer

    Accuracy is the proportion of correctly predicted samples out of total samples: correct predictionstotal predictions\frac{\text{correct predictions}}{\text{total predictions}}total predictionscorrect predictions​.

    Explanation

    For binary classification, it's a simple metric but can be misleading for imbalanced classes.

  15. 15

    Define precision and recall with respect to a binary classification task.

    Model answer

    Precision is TPTP+FP\frac{TP}{TP+FP}TP+FPTP​ (how many predicted positives are actually positive); recall is TPTP+FN\frac{TP}{TP+FN}TP+FNTP​ (how many actual positives were captured by the model).

    Explanation

    High precision means low false positives; high recall means low false negatives. They are often traded off.

  16. 16

    What is the F1 score and why is it useful?

    Model answer

    F1 score is the harmonic mean of precision and recall: 2×precision×recallprecision+recall2 \times \frac{\text{precision} \times \text{recall}}{\text{precision} + \text{recall}}2×precision+recallprecision×recall​. It balances both metrics, especially for imbalanced datasets.

    Explanation

    Accuracy can be misleading when classes are imbalanced; F1 provides a single score that considers both false positives and false negatives.

  17. 17

    Explain how K-Nearest Neighbors (KNN) makes predictions.

    Model answer

    KNN predicts the label of a new point by finding the K closest training points (using a distance metric like Euclidean distance) and taking the majority vote (for classification) or average (for regression).

    Explanation

    It's a non-parametric, instance-based learning algorithm that requires storing all training data. Choice of K and distance metric affects performance.

  18. 18

    What is Euclidean distance? Give its formula for two points (x1,y1)(x_1, y_1)(x1​,y1​) and (x2,y2)(x_2, y_2)(x2​,y2​).

    Model answer

    Euclidean distance is the straight-line distance between two points: (x1−x2)2+(y1−y2)2\sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}(x1​−x2​)2+(y1​−y2​)2​.

    Explanation

    It can be extended to n dimensions by summing squared differences across all features.

  19. 19

    How does Naive Bayes classify data?

    Model answer

    Naive Bayes applies Bayes' theorem with the 'naive' assumption that features are independent given the class. It calculates the posterior probability P(Ck∣x)∝P(Ck)∏iP(xi∣Ck)P(C_k | x) \propto P(C_k) \prod_i P(x_i | C_k)P(Ck​∣x)∝P(Ck​)∏i​P(xi​∣Ck​) and picks the class with maximum probability.

    Explanation

    Despite the independence assumption, it often performs well, especially on text data. It's fast and requires little training data.

  20. 20

    State Bayes' rule for conditional probability.

    Model answer

    P(A∣B)=P(B∣A)P(A)P(B)P(A|B) = \frac{P(B|A) P(A)}{P(B)}P(A∣B)=P(B)P(B∣A)P(A)​.

    Explanation

    It relates the conditional probability of A given B to the likelihood, prior, and evidence.

  21. 21

    What is logistic regression and why is it called 'logistic'?

    Model answer

    Logistic regression models the probability of a binary outcome using the logistic (sigmoid) function: P(y=1∣x)=11+e−(β0+β1x)P(y=1|x) = \frac{1}{1+e^{-(\beta_0 + \beta_1 x)}}P(y=1∣x)=1+e−(β0​+β1​x)1​. It is used for classification despite the name 'regression'.

    Explanation

    The sigmoid function maps linear combinations to probabilities between 0 and 1. The decision boundary is at probability 0.5.

  22. 22

    Explain the sigmoid function and its role in logistic regression.

    Model answer

    The sigmoid function is σ(z)=11+e−z\sigma(z) = \frac{1}{1+e^{-z}}σ(z)=1+e−z1​, outputting values between 0 and 1. In logistic regression, it transforms the linear combination of features into a probability.

    Explanation

    It is S-shaped, differentiable, and maps any real number to (0,1), making it suitable for binary classification.

  23. 23

    What is a support vector machine (SVM)?

    Model answer

    SVM finds a hyperplane that best separates classes by maximizing the margin (distance to the nearest points from each class, called support vectors).

    Explanation

    It can handle non-linear data using kernel tricks (e.g., polynomial, RBF) to map to higher dimensions.

  24. 24

    What are support vectors in SVM?

    Model answer

    Support vectors are the data points closest to the decision boundary (hyperplane) that define the margin; they are critical for determining the hyperplane.

    Explanation

    Only support vectors influence the classifier; removing other points does not change the model.

  25. 25

    What is the kernel trick in SVM?

    Model answer

    The kernel trick allows SVM to work in high-dimensional feature spaces without explicitly computing coordinates, by using a kernel function (e.g., RBF) that computes dot products in the transformed space.

    Explanation

    It enables non-linear decision boundaries by implicitly mapping data to a higher dimension where separation becomes linear.

  26. 26

    Describe the basic structure of a neural network: input layer, hidden layers, output layer.

    Model answer

    A neural network consists of an input layer (features), one or more hidden layers (activation functions applied), and an output layer (predictions). Each layer has neurons connected by weighted edges.

    Explanation

    Weights are learned via backpropagation. Activation functions (ReLU, sigmoid, tanh) introduce non-linearity, preventing the network from collapsing into a linear model.

  27. 27

    Why are activation functions necessary in neural networks?

    Model answer

    Without activation functions, the entire network becomes a linear combination of inputs, losing representational power. Activation functions introduce non-linearity, enabling learning of complex patterns.

    Explanation

    Common activations: ReLU (f(x)=max(0,x)), sigmoid (0 to 1), tanh (-1 to 1). They allow layers to stack and model non-linear relationships.

  28. 28

    What is gradient descent and how does it update weights?

    Model answer

    Gradient descent minimizes loss by computing the gradient of the loss w.r.t. each weight and updating weights in the opposite direction: wnew=wold−α∂L∂ww_{\text{new}} = w_{\text{old}} - \alpha \frac{\partial L}{\partial w}wnew​=wold​−α∂w∂L​, where α\alphaα is the learning rate.

    Explanation

    It iteratively moves towards the minimum of the loss function. Backpropagation efficiently computes gradients in neural networks.

  29. 29

    What is the learning rate in gradient descent?

    Model answer

    The learning rate α\alphaα controls the step size of weight updates. Too high can cause divergence; too low slows convergence.

    Explanation

    It is a hyperparameter that must be tuned. Common values: 0.01, 0.001.

  30. 30

    What is dropout in neural networks and why is it used?

    Model answer

    Dropout randomly deactivates a fraction of neurons during training, preventing overfitting by forcing the network to learn redundant representations.

    Explanation

    It acts as regularization; at test time, all neurons are used with scaled weights.

  31. 31

    Explain the concept of residual (error) in linear regression.

    Model answer

    A residual is the difference between the actual value yiy_iyi​ and predicted value y^i\hat{y}_iy^​i​: ei=yi−y^ie_i = y_i - \hat{y}_iei​=yi​−y^​i​. It measures the error for a single data point.

    Explanation

    Linear regression aims to minimize the sum of squared residuals (or absolute residuals).

  32. 32

    Write the equation for simple linear regression and explain each term.

    Model answer

    y=b0+b1xy = b_0 + b_1 xy=b0​+b1​x, where yyy is the predicted value, b0b_0b0​ is the y-intercept, b1b_1b1​ is the slope, and xxx is the feature.

    Explanation

    It models a linear relationship between one feature and the target.

  33. 33

    What are the assumptions of linear regression?

    Model answer

    Linearity (linear relationship between features and target), independence (observations independent), normality (residuals normally distributed), homoscedasticity (constant variance of residuals).

    Explanation

    Violations may require transformation or alternative models.

  34. 34

    Define mean absolute error (MAE) and give its formula.

    Model answer

    MAE is the average absolute difference between predicted and actual values: MAE=1n∑i=1n∣yi−y^i∣\text{MAE} = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|MAE=n1​∑i=1n​∣yi​−y^​i​∣.

    Explanation

    It is in the same units as the target, easy to interpret.

  35. 35

    Define mean squared error (MSE) and root mean squared error (RMSE).

    Model answer

    MSE is the average squared difference: 1n∑(yi−y^i)2\frac{1}{n} \sum (y_i - \hat{y}_i)^2n1​∑(yi​−y^​i​)2. RMSE is the square root of MSE: MSE\sqrt{\text{MSE}}MSE​, in same units as target.

    Explanation

    MSE penalizes large errors more; RMSE is more interpretable.

  36. 36

    Explain R-squared (R2R^2R2) and what a value close to 1 indicates.

    Model answer

    R2=1−SSresSStotR^2 = 1 - \frac{SS_{res}}{SS_{tot}}R2=1−SStot​SSres​​, where SSres=∑(yi−y^i)2SS_{res} = \sum (y_i - \hat{y}_i)^2SSres​=∑(yi​−y^​i​)2 and SStot=∑(yi−yˉ)2SS_{tot} = \sum (y_i - \bar{y})^2SStot​=∑(yi​−yˉ​)2. It measures the proportion of variance explained by the model; close to 1 means good fit.

    Explanation

    It compares model performance to a baseline (mean predictor). Does not indicate causality.

  37. 37

    What is K-means clustering and what does the 'K' represent?

    Model answer

    K-means partitions data into K clusters by minimizing within-cluster variance. K is the number of clusters, predefined by the user.

    Explanation

    The algorithm iteratively assigns points to nearest centroid and recalculates centroids until convergence.

  38. 38

    Describe the steps of the K-means algorithm.

    Model answer
    1. Initialize K random centroids. 2. Assign each point to the nearest centroid (expectation). 3. Recompute centroids as mean of assigned points (maximization). 4. Repeat steps 2-3 until assignments no longer change.

    Explanation

    This is the Expectation-Maximization (EM) approach. It converges to a local optimum.

  39. 39

    What is PCA and why is it used?

    Model answer

    Principal Component Analysis (PCA) is a dimensionality reduction technique that finds directions (principal components) of maximum variance in the data, projecting data onto a lower-dimensional space while preserving as much variance as possible.

    Explanation

    It reduces the number of features, mitigates the curse of dimensionality, and can reveal hidden structure.

  40. 40

    How does PCA achieve dimensionality reduction?

    Model answer

    PCA transforms the original features into a new set of orthogonal components ordered by variance. The first few components capture most variance, allowing data to be approximated with fewer dimensions.

    Explanation

    Mathematically, it finds eigenvectors of the covariance matrix. The projection residuals are minimized, and variance is maximized.

  41. 41

    Why is feature scaling important for many machine learning models?

    Model answer

    Algorithms like SVM, KNN, and neural networks are sensitive to feature scales; unscaled features with larger magnitudes can dominate distance calculations and gradient updates.

    Explanation

    Standardization (z-score) or normalization (min-max) ensures each feature contributes equally.

  42. 42

    What is the purpose of oversampling in imbalanced datasets?

    Model answer

    Oversampling increases the number of minority class samples (e.g., by duplicating or synthesizing) to balance class distribution, preventing the model from being biased toward the majority class.

    Explanation

    Random oversampler duplicates random samples; SMOTE creates synthetic samples. It is applied only to the training set to avoid leaking information into validation/test.

  43. 43

    What is the difference between validation set and test set?

    Model answer

    Validation set is used during model development to tune hyperparameters or compare models; test set is held out until the end to evaluate final generalization performance.

    Explanation

    Using the test set multiple times would bias performance estimates. Validation provides intermediate feedback.

  44. 44

    How do you handle categorical labels when the computer requires numerical input?

    Model answer

    Map categories to numbers, e.g., using one-hot encoding for nominal data or integer encoding for ordinal data.

    Explanation

    ML models require numeric input; mapping must preserve information appropriately (no order for nominal, order for ordinal).

1 of 44
Question 1 of 44

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent