ML Study Hub

Home / Past papers / MLP End Term / this paper

2023 Dec24: IIT M FN EXAM FDD1 - 24 Dec 2023

MLP End Term38 questions100 marks22 MCQ · 11 MSQ · 5 SAforenoon
Elapsed 00:00
Q1MCQ2 marks
Consider the following Python code using Pandas: question figure Consider the following Python code using Pandas: What does the groupby operation in the code achieve?
  1. It calculates the total price for each category.
  2. It calculates the average price for each category.
  3. It groups the data by the ’Category’ column.
  4. It filters out rows where the ’Price’ column is zero.
Q2MCQ2 marks
question figure
  1. question figure
  2. question figure
  3. question figure
  4. question figure
Q3MCQ2 marks
Which of the following metrics indicate higher their value, better the regression model’s performance?
  1. RMSE
  2. R2
  3. Mean absolute error
  4. Mean squared error
Q4MCQ2 marks
Which of the following variations of gradient descent can be implemented with SGDClassifier?
  1. stochastic gradient descent
  2. mini gradient descent
  3. full batch gradient descent
  4. None of these
Q5MCQ2 marks
Consider the Ridge regression model in scikit-learn, represented by the Ridge class. Which of the following statements about Ridge regression is correct?
  1. Ridge regression is designed to handle class imbalance of the dataset.
  2. The regularization term in Ridge regression is added to the sum of absoluteresiduals.
  3. Increasing the value of the regularization parameter (alpha) in Ridgeregression makes the model less sensitive to high-magnitude coefficients.
  4. Ridge regression is equivalent to Lasso regression when the regularizationparameter (alpha) is set to zero.
Q6MCQ2 marks
Which of the following method is used to estimate the probabilities in SGD-Classifier with suitable loss?
  1. question figure
  2. question figure
  3. question figure
  4. question figure
Q7MCQ2 marks
question figure
  1. Faster to compute the list of neighbors on scaled data.
  2. k-nearest neighbors is based on computing some distances. Features need tobe normalized to contribute approximately equally to the distance computation.
  3. Scaling the data has a negligible effect on k-nearest neighbor’s performance,but it enhances the interpretability of the model.
  4. This is irrelevant. One could use k-nearest neighbors without normalizing thedataset and get a very similar cross-validation score.
Q8MCQ2 marks
When using CountVectorizer in scikit-learn, what does the max_features parameter control?
  1. The maximum number of documents considered during vectorization.
  2. The maximum number of features (words) to be extracted based on termfrequency.
  3. The maximum number of randomly selected features (words).
  4. The maximum number of characters allowed in each document.
Q9MCQ2 marks
Which of these may NOT help in handling overfitting in decision trees?
  1. Increasing the value of min_samples_split
  2. Increasing the value of the pruning parameter
  3. Increasing the value of min_samples_leaf
  4. Increasing the depth of the tree
Q10MCQ2 marks
Which of the following is/are Clustering Method.
  1. Connectivity-based Clustering
  2. Centroids-based Clustering
  3. Density-based Clustering
  4. All of them
Q11MCQ2 marks
You’re working with a large image and want to group similarly coloured segments in the image together. No other information is provided with the image. Which of the following techniques will you use to accomplish the task?
  1. Supervised learning
  2. Unsupervised learning
  3. Reinforcement learning
  4. None of these
Q12MCQ2 marks
question figure
  1. logistic
  2. relu
  3. identity
  4. tanh
Q13MCQ3 marks
question figure
  1. [5, 5, 3.75]
  2. [5, 5, 3]
  3. [4, 4, 3]
  4. [4, 4, 3.75]
Q14MCQ3 marks
question figure
  1. question figure
  2. question figure
  3. question figure
  4. question figure
Q15MCQ3 marks
Which of the following code snippets represent correct methods to obtain cross validated performance measure using LeaveOneOut?
  1. question figure
  2. question figure
  3. question figure
  4. question figure
  5. question figure
Q16MCQ3 marks
question figure
  1. (71)
  2. (71, 1)
  3. (10)
  4. (10, 2)
Q17MCQ3 marks
You’re building an ‘MLPClassifier‘ for a dataset with a large number of features. The goal is to predict whether a patient is going to have parkinson disease in next 12 months. You’re trying to decide the appropriate number of neurons in the hidden layers of the neural network. Which statement about adjusting the hidden_layer_sizes parameter is correct?
  1. Increasing the number of neurons in hidden layers will always lead to bettermodel performance.
  2. Decreasing the number of neurons in hidden layers reduces the model’scapacity to capture complex patterns.
  3. The number of neurons in hidden layers does not significantly affect themodel’s performance.
  4. Finding the optimal number of neurons is a trial-and-error process and mayrequire experimentation.
Q18MCQ3 marks
Which of the following code snippet can correctly plot the elbow graph for feature matrix X (k value is taken from 1 to 10)?
  1. question figure
  2. question figure
  3. question figure
  4. question figure
  5. question figure
Q19MCQ3 marks
question figure
  1. Increasing the model’s complexity to fit the training data more closely.
  2. Adding a stronger regularization term to the loss function, discouragingcomplex models.
  3. Making the model more capable to learn more complex behaviour.
  4. Adjusting the learning rate to control convergence speed.
Q20MCQ4 marks
question figure
  1. Output score is likely to increase.
  2. Output score is likely to decrease.
  3. Output score may increase or decrease.
  4. Output score will remain the same.
Q21MCQ4 marks
question figure
  1. 0
  2. 1
  3. 2
  4. 3
Q22MCQ4 marks
question figure
  1. Above code uses bootstrapping to generate samples for each base classifier.
  2. model will be tested on out of the bags samples.
  3. Due to weights=’distance’, each base KNN classifier will treat all neighborsequally in terms of voting power.
  4. The ensemble will consist of 3 base KNN classifiers.
  5. None of these
Q23MSQ2 marksselect all that apply
Consider a dataset representing various attributes of red wine, loaded into a Pandas DataFrame named data using the following code: question figure Consider a dataset representing various attributes of red wine, loaded into a Pandas DataFrame named data using the following code: Suppose we are interested in extracting the value of the chlorides attribute for the third sample in the dataset (2nd by index). Which of the following expressions correctly achieves this? chlorides is at the 4th index of columns.
  1. data.chlorides[2]
  2. data[’chlorides’][2]
  3. data[2][4]
  4. data.iloc[2, 4]
Q24MSQ2 marksselect all that apply
question figure
  1. It applies lasso penalty.
  2. The training may terminate after 499 iterations or lesser
  3. the classifier represents a perceptron model
  4. The classifier’s model parameters will initialized with parameters learnt fromprevious call to fit() function, if the same object is trained/fitted multiple times on new data.
Q25MSQ2 marksselect all that apply
Which of the following observations warrant use of SGD model?
  1. The data set size is 1000 GB.
  2. The model has to be trained in non-iterative manner.
  3. The model must be a decision tree.
  4. The model must be a logistic regressor.
  5. None of these
Q26MSQ2 marksselect all that apply
question figure
  1. question figure
  2. question figure
  3. question figure
  4. question figure
Q27MSQ2 marksselect all that apply
question figure
  1. ‘poly’,
  2. ‘lasso’
  3. ‘rbf’,
  4. ‘scale’
Q28MSQ3 marksselect all that apply
question figure
  1. malic_acid
  2. magnesium
  3. flavanoids
  4. proanthocyanins
  5. color_intensity
  6. proline
Q29MSQ3 marksselect all that apply
question figure
  1. question figure
  2. question figure
  3. question figure
  4. question figure
Q30MSQ3 marksselect all that apply
question figure
  1. [47, 31, 18, 95, 77]
  2. [47, 31, 18 ]
  3. [31, 41, 18, 95, 85, 77]
  4. [31, 41, 85, 31]
  5. [18, 95, 85, 77]
  6. [47, 31, 18, 85]
  7. None of these
Q31MSQ3 marksselect all that apply
When using a Support Vector Classifier (SVC) in scikit-learn with different values of the regularization parameter (C), how does the complexity of the decision boundary change? Select all correct statements:
  1. Smaller values of C result in a more complex decision boundary.
  2. Larger values of C result in a more complex decision boundary.
  3. The decision boundary becomes simpler with increasing values of C.
  4. Very large values of C may lead to overfitting.
Q32MSQ4 marksselect all that apply
question figure
  1. Number of samples at node N = 10. If it is split, it will result in 2 nodes in theleft child and 8 nodes in the right child.
  2. Number of samples at node N = 6. If it is split, it will result in 3 nodes in the leftchild and 3 nodes in the right child.
  3. Number of samples at node N = 12. If it is split, it will result in 5 nodes in theleft child and 7 nodes in the right child.
  4. Number of samples at node N = 4. If it is split, it will result in 3 nodes in the leftchild and 1 node in the right child.
Q33SA3 marks
question figure
Q34SA3 marks
question figure
Q35SA2 marks
question figure
Q36SA4 marks
question figure
Comprehension passage - the questions below it refer to this
Based on the above data, answer the given subquestions. question figure
Q37SA3 marks
How many Accidents per 1000 Driver happens for Age 25 and driving blue car ?
Q38MSQ2 marksselect all that apply
To improve the given model which of the following preprocessing step you suggest?
  1. StandardScaler()
  2. OrdinalEncoder()
  3. MinMaxScaler()
  4. LabelEncoder()

Answer key

  1. Q1 (MCQ, 2 marks): B
  2. Q2 (MCQ, 2 marks): D
  3. Q3 (MCQ, 2 marks): B
  4. Q4 (MCQ, 2 marks): A
  5. Q5 (MCQ, 2 marks): C
  6. Q6 (MCQ, 2 marks): A
  7. Q7 (MCQ, 2 marks): B
  8. Q8 (MCQ, 2 marks): B
  9. Q9 (MCQ, 2 marks): D
  10. Q10 (MCQ, 2 marks): D
  11. Q11 (MCQ, 2 marks): B
  12. Q12 (MCQ, 2 marks): C
  13. Q13 (MCQ, 3 marks): B
  14. Q14 (MCQ, 3 marks): B
  15. Q15 (MCQ, 3 marks): A
  16. Q16 (MCQ, 3 marks): C
  17. Q17 (MCQ, 3 marks): D
  18. Q18 (MCQ, 3 marks): C
  19. Q19 (MCQ, 3 marks): C
  20. Q20 (MCQ, 4 marks): A
  21. Q21 (MCQ, 4 marks): B
  22. Q22 (MCQ, 4 marks): E
  23. Q23 (MSQ, 2 marks): A, B, D
  24. Q24 (MSQ, 2 marks): B, D
  25. Q25 (MSQ, 2 marks): A, D
  26. Q26 (MSQ, 2 marks): A, C
  27. Q27 (MSQ, 2 marks): A, C
  28. Q28 (MSQ, 3 marks): C, E, F
  29. Q29 (MSQ, 3 marks): A, C, D
  30. Q30 (MSQ, 3 marks): A, B, C, D
  31. Q31 (MSQ, 3 marks): B, D
  32. Q32 (MSQ, 4 marks): A, D
  33. Q33 (SA, 3 marks): 0.6
  34. Q34 (SA, 3 marks): 1
  35. Q35 (SA, 2 marks): 2
  36. Q36 (SA, 4 marks): 500
  37. Q37 (SA, 3 marks): 73 to 75
  38. Q38 (MSQ, 2 marks): A, C

Concepts this paper tests

Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.

Here’s a structured summary of core topics, concepts, principles, and equations essential for the Diploma Level: Machine Learning Practice (Computer-Based Exam). The exam covers Pandas, scikit-learn, ML algorithms, preprocessing, model evaluation, hyperparameter tuning, and clustering. --- ---

1. Core Topics & Concepts

A. Data Preprocessing

  1. StandardScaler

    • Standardizes features to have mean = 0 and std = 1.
    • Formula:
z=x−μσz = \frac{x - \mu}{\sigma}
  1. One-Hot Encoding (OneHotEncoder)

    • Converts categorical features into binary columns.
    • Avoids ordinal bias (unlike LabelEncoder).
    • Example:

      from sklearn.preprocessing import OneHotEncoder
      ohe = OneHotEncoder(sparse_output=False)
      encoded = ohe.fit_transform(df[['category']])
  1. Feature Selection (SelectKBest)

    • Selects top k features based on statistical tests (e.g., chi2, f_classif).
    • Example:

      from sklearn.feature_selection import SelectKBest, chi2
      skb = SelectKBest(chi2, k=3)
      X_selected = skb.fit_transform(X, y)
  1. Train-Test Split

    • Splits data into training and testing sets.
    • Example:

      from sklearn.model_selection import train_test_split
      X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

B. Supervised Learning

  1. Linear Regression

    • Predicts continuous output using linear relationship:
y=β0+β1x1+⋯+βnxny = \beta_0 + \beta_1 x_1 + \dots + \beta_n x_n
  1. Ridge Regression (L2 Regularization)

    • Penalizes large coefficients to prevent overfitting.
    • Loss function:
MSE+α∑i=1nβi2\text{MSE} + \alpha \sum_{i=1}^n \beta_i^2
  1. Decision Trees

    • Splits data based on feature thresholds to minimize impurity (Gini/entropy).
    • Hyperparameters:

      • max_depth: Maximum tree depth.
      • min_samples_split: Minimum samples required to split a node.
      • min_samples_leaf: Minimum samples required in a leaf.
    • Overfitting Risk: Deeper trees → higher variance.
  1. Support Vector Machines (SVM)

    • Finds the optimal hyperplane to separate classes.
    • Kernel Trick: Transforms data into higher dimensions (linear, poly, rbf).
    • Regularization Parameter (C):

      • Small C → wider margin (simpler model).
      • Large C → narrower margin (complex model, risk of overfitting).
  1. k-Nearest Neighbors (KNN)

    • Classifies based on majority vote of k nearest neighbors.
    • Distance Metrics: Euclidean, Manhattan.
    • Why Scale? Features must be normalized to avoid bias toward high-magnitude features.
  1. Stochastic Gradient Descent (SGD)

    • Optimizes loss functions iteratively (used in SGDClassifier, SGDRegressor).
    • Variants:

      • Full Batch: Uses entire dataset per update.
      • Mini-Batch: Uses random subset (mini-batch) per update.
      • Stochastic: Uses 1 sample per update.
    • Loss Functions:

      • hinge (SVM), log_loss (logistic regression), squared_error (regression).
    • Regularization:

      • l1 (Lasso), l2 (Ridge), elasticnet (combination).
    • Hyperparameters:

      • alpha: Learning rate.
      • penalty: Regularization type.
      • max_iter: Maximum epochs.
  1. Neural Networks (MLPClassifier/MLPRegressor)

    • Activation Functions:

      • Hidden layers: relu, tanh, logistic.
      • Output layer:

        • Regression: identity.
        • Classification: logistic (binary) or softmax (multiclass).
    • Hyperparameters:

      • hidden_layer_sizes: Number of neurons per layer (e.g., (100, 50)).
      • activation: Activation function for hidden layers.
      • solver: Optimization algorithm (adam, sgd).

C. Model Evaluation

  1. Regression Metrics

    • R² (R-squared):

      • Range: [0, 1] (higher = better).
      • Formula:
R2=1−SSresSStotR^2 = 1 - \frac{\text{SS}_{\text{res}}}{\text{SS}_{\text{tot}}}
RMSE=1n∑i=1n(yi−y^i)2\text{RMSE} = \sqrt{\frac{1}{n} \sum_{i=1}^n (y_i - \hat{y}_i)^2}
MAE=1n∑i=1n∣yi−y^i∣\text{MAE} = \frac{1}{n} \sum_{i=1}^n |y_i - \hat{y}_i|
  1. Classification Metrics

    • Accuracy: (TP + TN) / (TP + TN + FP + FN).
    • Precision: TP / (TP + FP).
    • Recall: TP / (TP + FN).
    • F1-Score: Harmonic mean of precision and recall.
  1. Cross-Validation

    • k-Fold CV: Splits data into k folds; trains on k-1 folds, tests on 1.
    • Leave-One-Out (LOO): Extreme case of k-Fold where k = n_samples.
    • Example:

      from sklearn.model_selection import cross_val_score, KFold
      kf = KFold(n_splits=5)
      scores = cross_val_score(model, X, y, cv=kf)
  1. Grid Search & Random Search

    • GridSearchCV: Exhaustively searches all hyperparameter combinations.
    • RandomizedSearchCV: Samples random combinations (faster for large spaces).
    • Example:

      from sklearn.model_selection import GridSearchCV
      param_grid = {'C': [0.1, 1, 10], 'kernel': ['linear', 'rbf']}
      grid = GridSearchCV(SVC(), param_grid, cv=5)
      grid.fit(X, y)

D. Unsupervised Learning

  1. Clustering Methods

    • Centroid-Based (e.g., K-Means):

      • Assigns points to nearest centroid; updates centroids iteratively.
    • Density-Based (e.g., DBSCAN):

      • Groups points in dense regions; marks outliers.
    • Connectivity-Based (e.g., Hierarchical Clustering):

      • Builds a tree of clusters (agglomerative/divisive).
  1. Elbow Method (for K-Means)

    • Plots inertia (within-cluster sum of squares) vs. k to find optimal k.
    • Example:

      inertias = []
      for k in range(1, 11):
          kmeans = KMeans(n_clusters=k).fit(X)
          inertias.append(kmeans.inertia_)
      plt.plot(range(1, 11), inertias)

E. Ensemble Methods

  1. Random Forest

    • Ensemble of decision trees; reduces variance via bagging.
    • Hyperparameters:

      • n_estimators: Number of trees.
      • max_depth: Depth of each tree.
  1. Bagging (Bootstrap Aggregating)

    • Trains multiple models on bootstrapped samples; averages predictions.
    • Example: BaggingClassifier with KNeighborsClassifier.

F. Dimensionality Reduction

  1. Feature Selection vs. Extraction

    • Selection: Chooses subset of features (e.g., SelectKBest).
    • Extraction: Transforms features (e.g., PCA).

G. Pandas Operations

  1. GroupBy

    • Groups data by a column and applies aggregations (e.g., mean, sum).
    • Example:

      df.groupby('Category')['Price'].mean()
  1. Data Access

    • df['column'], df.column, df.iloc[row, col], df.loc[row_index, 'column'].

2. Key Equations

ConceptEquation
Standard Scalingz=x−μσz = \frac{x - \mu}{\sigma}
R² ScoreR2=1−SSresSStotR^2 = 1 - \frac{\text{SS}_{\text{res}}}{\text{SS}_{\text{tot}}}
RMSE1n∑(yi−y^i)2\sqrt{\frac{1}{n} \sum (y_i - \hat{y}_i)^2}
Ridge Regression LossMSE+α∑βi2\text{MSE} + \alpha \sum \beta_i^2
Linear Regressiony=β0+β1x1+⋯+βnxny = \beta_0 + \beta_1 x_1 + \dots + \beta_n x_n
SVM Margin (Hard)min⁡1∥w∥\min \frac{1}{\|w\|} s.t. yi(w⋅xi+b)≥1y_i(w \cdot x_i + b) \geq 1
KNN Distance (Euclidean)∑i=1n(xi−yi)2\sqrt{\sum_{i=1}^n (x_i - y_i)^2}
Decision Tree Gini Impurity1−∑pi21 - \sum p_i^2

Graph 2: Unsupervised Learning

Graph 3: Model Evaluation & Hyperparameter Tuning

Graph 4: scikit-learn Key Classes


4. Exam Tips

  1. Pandas:

    • Know groupby, iloc, loc, and column access methods.
  2. Preprocessing:

    • Always scale for distance-based models (KNN, SVM, K-Means).
    • Use OneHotEncoder for categorical features (avoid LabelEncoder for non-ordinal data).
  3. Model Selection:

    • Overfitting: Prune trees (max_depth, min_samples_leaf), use regularization (Ridge/Lasso).
    • Underfitting: Increase model complexity (deeper trees, more features).
  4. SGD:

    • warm_start=True retains weights between .fit() calls.
    • hinge loss → SVM; log_loss → logistic regression.
  5. Clustering:

    • K-Means: Needs scaled data; use the elbow method for k.
  6. Neural Networks:

    • Output layer activation:

      • Regression: identity.
      • Binary classification: logistic.
      • Multiclass: softmax.
  7. Hyperparameter Tuning:

    • GridSearchCV for small spaces; RandomizedSearchCV for large spaces.