ML Study Hub

Home / Past papers / MLP End Term / this paper

IIT M IMPROVEMENT FN EXAM QDD2 01 Sep - 01 Sep 2024

MLP End Term37 questions100 marks20 MCQ · 11 SA · 6 MSQImprovement / forenoon / QDD2
Elapsed 00:00
Comprehension passage - the questions below it refer to this
Consider following common data and answer the subquestions: question figure Consider following common data and answer the subquestions:
Q1SA2 marks
What will be the output of the following code snippet? question figure What will be the output of the following code snippet? Enter -1, if you think the above code snippet will generate an error.
Q2SA2 marks
What will be the output of the following code snippet? question figure What will be the output of the following code snippet? Enter -1, if you think the above code snippet will generate an error.
Q3SA2 marks
What will be the output of the following code snippet? question figure What will be the output of the following code snippet? Enter -1, if you think the above code snippet will generate an error.
Q4SA2 marks
How many columns have datatype as ”float64”?
Q5SA2 marks
What will be the output of the following code snippet? question figure What will be the output of the following code snippet? Enter -1, if you think the above code snippet will generate an error.
Q6SA2 marks
Consider following parameter grid for regression with RandomForest: question figure Consider following parameter grid for regression with RandomForest: How many unique combinations of hyperparameters are there in the above parameter grid?
Q7MCQ1 mark
How to make SGDRegressor stop after 1000 epochs?
  1. question figure
  2. question figure
  3. question figure
  4. question figure
Q8MCQ2 marks
question figure
  1. DictVectorizer
  2. HashingVectorizer
  3. FeatureHasher
Q9MCQ2 marks
Which of the following is an example of an ordinal variable?
  1. Blood type (A, B, AB, O)
  2. Satisfaction rating (Very Unsatisfied, Unsatisfied, Neutral, Satisfied, VerySatisfied)
  3. Height of individuals
  4. Gender
Q10MCQ2 marks
question figure
  1. question figure
  2. question figure
  3. question figure
  4. question figure
Q11MCQ2 marks
question figure
  1. cv
  2. reg_rate
  3. alpha
  4. tol
Q12MCQ3 marks
question figure
  1. 1000
  2. 100
  3. 99
  4. 999
Q13MCQ3 marks
question figure
  1. question figure
  2. question figure
  3. question figure
  4. question figure
Q14MCQ3 marks
question figure
  1. It determines whether to include a bias term in the model.
  2. It sets the degree of the polynomial features.
  3. It controls the regularization strength.
  4. It specifies the number of features to consider when fitting the model.
Q15MCQ3 marks
question figure
  1. To specify the maximum number of samples per leaf.
  2. To limit the depth of the tree.
  3. To set the minimum number of samples required to split an internal node.
  4. To control the minimum impurity decrease required for a split.
Q16MCQ3 marks
question figure
  1. It determines the function to measure the quality of a split.
  2. It specifies the number of features to consider when looking for the best split.
  3. It sets the strategy used to choose the split at each node.
  4. It controls whether to use the Gini impurity or entropy.
Q17MCQ3 marks
question figure
  1. question figure
  2. question figure
  3. question figure
  4. question figure
Q18MCQ3 marks
Consider below statements and choose the correct option: Statement1:The bagging technique combines multiple models trained on different subsets of data Statement2:The Boosting technique trains the model Parallelly, focusing on the error made by the other model.
  1. Statement1 is True, Statement2 is True
  2. Statement1 is True, Statement2 is False
  3. Statement1 is False, Statement2 is True
  4. Statement1 is False, Statement2 is False
Q19MCQ3 marks
How does agglomerative clustering handle outliers?
  1. It ignores outliers during the clustering process.
  2. It assigns outliers to the nearest cluster.
  3. It creates separate clusters for outliers.
  4. It removes outliers from the dataset before clustering.
Q20MCQ3 marks
What is agglomerative clustering?
  1. A hierarchical clustering technique that starts with each data point as itscluster and merges the closest clusters iteratively.
  2. A method for partitioning data into a predefined number of clusters.
  3. A clustering algorithm that uses centroids to iteratively assign data points toclusters.
  4. A dimensionality reduction technique that projects data onto a lower-dimensional space.
Q21MCQ3 marks
question figure
  1. The distance between cluster centroids
  2. The number of clusters formed
  3. The within-cluster sum of squared distances
  4. The silhouette coefficient
Q22MCQ4 marks
Consider the following ML task/steps for a regression dataset: 1. Read the data from a file (named ‘dataset.csv’). It has 7 columns. The last column is the target variable, all 6 features numerical. 2. Remove rows which has target values missing. 3. Split the data into training and test sets. Take randomly the 70% of rows in the training set and the rest of them into the test set. 4. Fill the missing values in the features by KNNImputer using 3 nearest neighbours. 5. Train a LinearRegression model on the training set. 6. Report R2 score on the test set. Which of the following code snippets correctly accomplishes the above task? Assume necessary imports.
  1. question figure
  2. question figure
  3. question figure
  4. question figure
  5. question figure
  6. question figure
Q23MCQ4 marks
question figure
  1. question figure
  2. question figure
  3. question figure
  4. question figure
Q24MCQ4 marks
question figure
  1. question figure
  2. question figure
  3. question figure
  4. question figure
  5. question figure
Q25MCQ4 marks
question figure
  1. The predictions are based on the majority vote.
  2. The predictions are based on the average of probabilities predicted by eachclassifier.
  3. The predictions are based on the weighted sum of the predictions.
  4. The predictions are based on the classifier with the highest accuracy
Q26MCQ4 marks
question figure
  1. 5 centroids are randomly initialized 10 times
  2. 10 centroids are randomly initialized 5 times
  3. 5 samples in the dataset are selected as initialization point such that they areat least 10 units away from each other
  4. 10 samples in the dataset are selected as initialization point such that they areat least 5 units away from each other
Q27MSQ2 marksselect all that apply
Data snooping:
  1. Leads to biased estimation on test sets
  2. Increases the risk of false positives
  3. Leads to better estimation on training sets
  4. Reduces the risk of false positives
Q28MSQ2 marksselect all that apply
Which of the following algorithms may get impacted by feature scaling?
  1. LinearRegression
  2. DecisionTree
  3. SVM
  4. NaiveBayes
Q29MSQ3 marksselect all that apply
question figure
  1. The logistic regression model will use equal weights for both the classes in animbalanced dataset.
  2. The model does not use any regularization because the parameter C is set.
  3. The “balanced” mode uses the values of y to automatically adjust weightsinversely proportional to class frequencies in the input data.
  4. The value of C indicates that the model will apply a regularization.
Q30MSQ3 marksselect all that apply
Which of the following statements are true?
  1. KNeighborsClassifier with high values of n_neighbors produces complexdecision boundaries.
  2. KNeighborsClassifier with high values of n_neighbors produces smoothdecision boundaries.
  3. In KNeighborsClassifier the scale of the features(columns) can impact thedecision boundaries.
  4. None of these
Q31MSQ3 marksselect all that apply
Which options are correct for Support Vectors in SVM ?
  1. Support vectors are the data points nearest to the hyperplane
  2. Using these support vectors, we maximize the margin of the classifier.
  3. Using these support vectors, we minimize the margin of the classifier.
  4. None of these
Q32MSQ3 marksselect all that apply
Which of the following are correct for Kmeans clustering algorithm?
  1. It only finds spherical clusters.
  2. The output of the algorithms depends upon initial cluster centroids.
  3. It can automatically detect most appropriate value of k.
  4. None of these.
Q33SA3 marks
question figure
Q34SA3 marks
question figure
Q35SA3 marks
question figure
Comprehension passage - the questions below it refer to this
Based on the above data, answer the given subquestions. question figure
Q36SA2 marks
What will be the output of the following code? question figure What will be the output of the following code?
Q37SA2 marks
What will be the output of the following code? question figure What will be the output of the following code?

Answer key

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

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, and clustering. ---


1. Core Topics & Concepts

A. Pandas & Data Handling

Key Concepts:

  1. DataFrame Operations:

    • Shape: df.shape → (rows, columns).
    • Missing values: df.isna().sum().sum() → Total missing values.
    • Value counts: df.column.value_counts() → Frequency of unique values.
    • Querying: df.query("condition") → Filter rows.
    • Indexing: df.iloc[:, n] → Select column n; df.loc[index, column] → Select by label.
    • Mean/aggregations: df.column.mean() (ignores NaN by default).
  1. Handling Missing Data:

    • Drop: df.dropna().
    • Impute: KNNImputer(n_neighbors=k) (for numerical data).
  1. Data Types:

    • float64 (default for decimals), int64, object (strings/categorical).
    • Check dtypes: df.dtypes.

Key Equations (Pandas):

Mean=∑i=1nxicount of non-NaN values\text{Mean} = \frac{\sum_{i=1}^{n} x_i}{\text{count of non-NaN values}}

B. Scikit-Learn Workflow

Key Concepts:

  1. Data Preprocessing:

    • Scaling:

      • StandardScaler (standardizes to mean=0, std=1).
      • MinMaxScaler (scales to [0, 1]).
    • Polynomial Features:

      • PolynomialFeatures(degree=d, include_bias=True/False).
      • If include_bias=True, adds a column of 1s (for intercept).
    • Encoding:

      • DictVectorizer (for feature extraction from dictionaries).
      • OneHotEncoder (for categorical variables).
  1. Train-Test Split:

    • train_test_split(X, y, test_size=0.3, random_state=42).
    • random_state ensures reproducibility.
  1. Pipelines:

    • make_pipeline(step1, step2, ...) → Sequential processing (e.g., impute → scale → model).
    • Example:

      pipe = Pipeline([
          ('imputer', KNNImputer(n_neighbors=3)),
          ('scaler', StandardScaler()),
          ('model', LinearRegression())
      ])
  1. Model Evaluation:

    • Regression: R² score (model.score(X_test, y_test)).
    • Classification:

      • precision_score, recall_score, confusion_matrix.
      • DummyClassifier(strategy='most_frequent') → Predicts the majority class.

Key Equations (Preprocessing):

xscaled=x−μσx_{\text{scaled}} = \frac{x - \mu}{\sigma}

where μ\mu = mean, σ\sigma = standard deviation.

xscaled=x−xmin⁡xmax⁡−xmin⁡x_{\text{scaled}} = \frac{x - x_{\min}}{x_{\max} - x_{\min}}

C. Supervised Learning Algorithms

1. Linear Models

ModelKey ParametersUse CaseEquation
LinearRegression-Regressiony^=wTx+b\hat{y} = w^T x + b (closed-form solution via OLS)
RidgeRegressionalpha (regularization strength)Regression (L2 penalty)min⁡∥y−Xw∥22+α∥w∥22\min \|y - Xw\|_2^2 + \alpha \|w\|_2^2
LassoRegressionalphaRegression (L1 penalty, sparsity)min⁡∥y−Xw∥22+α∥w∥1\min \|y - Xw\|_2^2 + \alpha \|w\|_1
SGDRegressormax_iter, tol, learning_rateLarge datasetsIterative update: w=w−η∇Lossw = w - \eta \nabla \text{Loss}
LogisticRegressionC (inverse of alpha), class_weightBinary classificationP(y=1)=σ(wTx)P(y=1) = \sigma(w^T x), where σ\sigma = sigmoid function.
Perceptrontol, shuffleLinear classificationy^=sign(wTx)\hat{y} = \text{sign}(w^T x)

Key Notes:

2. Tree-Based Models

ModelKey ParametersUse CaseKey Concepts
DecisionTreemax_depth, min_samples_split, criterion (gini/entropy for classification, mse/mae for regression)Classification/RegressionSplits data recursively; max_depth limits tree depth to prevent overfitting.
RandomForestn_estimators, bootstrap, max_featuresEnsemble learningBagging (bootstrap aggregating) of decision trees.
BaggingClassifierbase_estimator, n_estimators, max_samplesReduce varianceTrains base models on bootstrapped samples.
VotingClassifierestimators, voting (hard/soft)Ensemble learningsoft voting averages predicted probabilities.

Key Notes:

3. Nearest Neighbors

ModelKey ParametersUse CaseKey Concepts
KNeighborsClassifiern_neighbors, weights (uniform/distance)ClassificationPredicts majority class of k nearest neighbors.
KNeighborsRegressorn_neighbors, weightsRegressionPredicts average of k nearest neighbors.

Key Notes:

4. Support Vector Machines (SVM)

ModelKey ParametersUse CaseKey Concepts
SVCC, kernel (linear, rbf), gammaClassificationMaximizes margin; C controls misclassification penalty.
SVRC, kernel, epsilonRegressionFits a tube around data; epsilon defines tube width.

Key Notes:


D. Unsupervised Learning

1. Clustering

ModelKey ParametersUse CaseKey Concepts
KMeansn_clusters, init (random/k-means++), n_initGeneral-purpose clusteringMinimizes within-cluster sum of squares (inertia).
AgglomerativeClusteringn_clusters, linkage (ward, complete, average)Hierarchical clusteringMerges closest clusters iteratively.

Key Notes:

Key Equations (Clustering):

Inertia=∑i=1nmin⁡μj∈C∥xi−μj∥2\text{Inertia} = \sum_{i=1}^{n} \min_{\mu_j \in C} \|x_i - \mu_j\|^2

where CC = set of centroids.


E. Model Evaluation & Metrics

1. Classification Metrics

MetricFormulaInterpretation
AccuracyTP+TNTP+TN+FP+FN\frac{\text{TP} + \text{TN}}{\text{TP} + \text{TN} + \text{FP} + \text{FN}}Overall correctness.
PrecisionTPTP+FP\frac{\text{TP}}{\text{TP} + \text{FP}}Correctness of positive predictions.
Recall (Sensitivity)TPTP+FN\frac{\text{TP}}{\text{TP} + \text{FN}}Ability to find all positive instances.
F1-Score2×Precision×RecallPrecision+Recall2 \times \frac{\text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}}Harmonic mean of precision and recall.
Confusion MatrixTP, TN, FP, FN for each class.

2. Regression Metrics

MetricFormulaInterpretation
R² Score1−∑(yi−y^i)2∑(yi−yˉ)21 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}Proportion of variance explained (1 = perfect fit).
MSE1n∑(yi−y^i)2\frac{1}{n} \sum (y_i - \hat{y}_i)^2Average squared error.

3. Cross-Validation

MethodDescriptionUse Case
Leave-One-Out (LOOCV)Uses n−1n-1 samples for training, 1 for testing (repeated nn times).Small datasets.
k-Fold CVSplits data into kk folds; each fold used once for testing.General-purpose.

Key Notes:


F. Hyperparameter Tuning

Key Concepts:

  1. Grid Search:

    • ParameterGrid generates all combinations of hyperparameters.
    • Example:

      param_grid = {
          'n_estimators': [10, 20, 30],
          'max_features': [2, 3, 4]
      }
    • Total combinations: 3×3=93 \times 3 = 9.
  1. Random Search: Samples randomly from parameter distributions.
  1. Common Parameters:

    • Random Forest: n_estimators, max_depth, min_samples_leaf.
    • SVM: C, kernel, gamma.
    • KNN: n_neighbors, weights.

G. Special Topics

1. Data Snooping

2. Feature Scaling Impact

3. Ordinal vs. Nominal Variables

TypeDefinitionExample
OrdinalCategories with order.Satisfaction (Low, Medium, High).
NominalCategories without order.Blood type (A, B, AB, O).

Graph 2: Unsupervised Learning

Graph 3: Model Evaluation

Graph 4: Scikit-Learn Ecosystem

Graph 5: Tree-Based Models

Graph 6: Clustering Algorithms


3. Key Equations Summary

TopicEquationDescription
Linear Regressiony^=wTx+b\hat{y} = w^T x + bPredicted value.
Ridge Regressionmin⁡∥y−Xw∥22+α∥w∥22\min \|y - Xw\|_2^2 + \alpha \|w\|_2^2L2 regularization.
Lasso Regressionmin⁡∥y−Xw∥22+α∥w∥1\min \|y - Xw\|_2^2 + \alpha \|w\|_1L1 regularization (sparsity).
Logistic RegressionP(y=1)=11+e−(wTx+b)P(y=1) = \frac{1}{1 + e^{-(w^T x + b)}}Sigmoid function for probabilities.
Perceptrony^=sign(wTx)\hat{y} = \text{sign}(w^T x)Linear classifier.
K-Means Inertia∑i=1nmin⁡μj∈C∥xi−μj∥2\sum_{i=1}^{n} \min_{\mu_j \in C} \|x_i - \mu_j\|^2Within-cluster sum of squares.
PrecisionTPTP+FP\frac{\text{TP}}{\text{TP} + \text{FP}}Correct positive predictions.
RecallTPTP+FN\frac{\text{TP}}{\text{TP} + \text{FN}}True positives found.
R² Score1−∑(yi−y^i)2∑(yi−yˉ)21 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}Variance explained.
Standard Scalingxscaled=x−μσx_{\text{scaled}} = \frac{x - \mu}{\sigma}Normalizes features.
Min-Max Scalingxscaled=x−xmin⁡xmax⁡−xmin⁡x_{\text{scaled}} = \frac{x - x_{\min}}{x_{\max} - x_{\min}}Scales to [0, 1].
Polynomial FeaturesFor [x1,x2][x_1, x_2], degree=2: [1,x1,x2,x12,x1x2,x22][1, x_1, x_2, x_1^2, x_1x_2, x_2^2]Generates interaction terms.

4. Exam Tips

  1. Pandas:

    • Memorize df.shape, df.isna().sum(), df.value_counts().
    • Practice indexing (iloc, loc) and querying (df.query).
  1. Scikit-Learn:

    • Know default parameters (e.g., RandomForestClassifier(n_estimators=100)).
    • Understand fit, predict, score methods.
    • Recall preprocessing steps (scaling, imputation, encoding).
  1. Algorithms:

    • Linear Models: Focus on regularization (alpha, C).
    • Tree-Based: Know max_depth, min_samples_split, bootstrap.
    • KNN: Remember scaling and n_neighbors.
    • SVM: Kernel trick and C parameter.
  1. Evaluation:

    • Classification: Precision, recall, F1, confusion matrix.
    • Regression: R², MSE.
    • Cross-validation: LOOCV vs. k-fold.
  1. Clustering:

    • K-Means: Inertia, n_init, scaling.
    • Agglomerative: Linkage methods (ward, complete).
  1. Hyperparameter Tuning:

    • Calculate total combinations for ParameterGrid.
    • Example: {'a': [1,2], 'b': [3,4]} → 4 combinations.
  1. Special Cases:

    • DummyClassifier: Predicts majority class.
    • DictVectorizer: For dictionary-to-feature matrix.
    • PolynomialFeatures: include_bias adds intercept term.
  1. Common Pitfalls:

    • Forgetting to scale data for KNN/SVM.
    • Misinterpreting class_weight='balanced'.
    • Confusing max_iter (SGD) with n_estimators (Random Forest).