Home / Past papers / MLP End Term / this paper
Which options represent the output of the following code block? 



Consider the following code block: What will be the value of the ‘count’?
Consider the following code block: 





Consider the following code 



Consider the following code:
Which of the following are correct about sklearn.svm.SVC: 







Consider following code snippets, assuming necessary imports. 



Consider the following code:
Following is the code to tune the n_estimators parameter of a Bagging Classifier model. 




Consider the following code. How many DecisionTreeClassifier models will be trained internally?
Consider two classifiers as shown in the following block of code:
Consider the following code:
Suppose that we use k-means clustering for a dataset having 100 samples. The initial centroids for k clusters can be initialized in multiple ways. One such as way is shown below 
















Consider the following block of code:
The code given below attempts to find the clusters in the dataset, X using the K-means algorithm.
The following line of code creates a neural network (assume necessary imports) Select the correct statements from the following list of statements
Consider the following code block: 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" exam, along with Mermaid knowledge graphs to visualize relationships.
Why Preprocess?
Key Methods:
train_test_split (e.g., test_size=0.3 for 70-30 split).StandardScaler/MinMaxScaler for feature scaling.OneHotEncoder for categorical features (e.g., 3 categories → 3 columns).KNNImputer for missing values (e.g., n_neighbors=3).Pipeline to chain transformations and estimators.Cross-Validation:
LeavePOut(p=2): Generates C(n_samples, p) splits (e.g., for n_samples=10, p=2 → 45 splits).RepeatedKFold(n_splits=3, n_repeats=2): Repeats K-Fold n_repeats times.GridSearchCV: Exhaustive search over hyperparameters (e.g., cv=3 for 3-fold CV).Classification:
Metrics:
confusion_matrix(y_true, y_pred)).Algorithms:
Logistic Regression:
multi_class='multinomial' + solver='lbfgs' for softmax regression.partial_fit for online learning (incremental updates).Decision Trees:
Hyperparameters:
min_samples_split (default=2), min_samples_leaf (default=1).ccp_alpha: Higher values → more pruning → shallower trees.min_samples_split/min_samples_leaf → deeper trees.SVM (SVC):
support_: Indices of support vectors.gamma: High gamma → tighter decision boundary (points must be very close to be in the same class).k-NN:
n_neighbors → more complex (less smooth) decision boundary.Neural Networks:
MLPClassifier/MLPRegressor in sklearn (e.g., hidden_layer_sizes=(3,5) → 2 hidden layers with 3 and 5 neurons).SGDClassifier:
loss="perceptron", loss="log" (logistic), loss="hinge" (SVM).partial_fit for online learning.Regression:
LinearRegression(fit_intercept=True).PolynomialFeatures(degree=2, interaction_only=True) generates interaction terms (e.g., for 3 features → 6 terms: original + 3 interactions).K-Means Clustering:
init='random': Randomly initialize centroids.n_init=10: Run algorithm 10 times with different centroids.K = n_samples.n_clusters > n_samples, it raises an error.Hyperparameters vs. Parameters:
C (SVM), n_estimators (Random Forest), learning_rate (SGD).GridSearchCV:
param_grid with max_depth and min_samples_split).param_grid = [{'A': [1,2]}, {'B': [3,4]}], total combinations = 2 (A) + 2 (B) = 4 (not 2×2, since separate dicts).stepname__param (e.g., bc__n_estimators for BaggingClassifier in a pipeline).Feature Selection:
Drop features with:
SelectKBest or SelectPercentile.| Concept | Equation |
|---|---|
| R² Score | |
| F1-Score | |
| Polynomial Features | For degree=2, interaction_only=True: (e.g., 3 features → 6 terms). |
| K-Means Inertia | |
| SGD Update (Perceptron) |
Confusion Matrix:
Example:
y_true = ["Rainy", "Sunny", "Sunny", "Rainy", "Sunny", "Rainy"]
y_pred = ["Sunny", "Sunny", "Rainy", "Rainy", "Sunny", "Sunny"]
Output: [[1, 2], [2, 1]] (Option C).
Polynomial Features:
interaction_only=True → Only interaction terms (no squares).n_features=3, degree=2 → 6 features (original 3 + 3 interactions).SGDClassifier:
loss="perceptron" → Perceptron.loss="log" → Logistic regression.loss="hinge" → Linear SVM.K-Means:
n_clusters > n_samples, it raises an error.init='random' initializes centroids randomly n_init times.Hyperparameter Tuning:
GridSearchCV, separate dictionaries in param_grid are treated as separate grids (not combined).param_grid = [{'A': [1,2]}, {'B': [3,4]}] → 2 + 2 = 4 combinations (not 4 total).Pipelines:
stepname__param for hyperparameter tuning (e.g., bc__n_estimators).R² Score:
Neural Networks in sklearn:
MLPClassifier/MLPRegressor (not NNClassifier).hidden_layer_sizes=(3,5) → 2 hidden layers (3 neurons, then 5 neurons).