Home / Past papers / MLP End Term / this paper
Consider following common data and answer the subquestions:
What will be the output of the following code snippet? Enter -1, if you think the above code snippet will generate an error.
What will be the output of the following code snippet? Enter -1, if you think the above code snippet will generate an error.
What will be the output of the following code snippet? Enter -1, if you think the above code snippet will generate an error.
What will be the output of the following code snippet? Enter -1, if you think the above code snippet will generate an error.
Consider following parameter grid for regression with RandomForest: How many unique combinations of hyperparameters are there in the above parameter grid?

















































What will be the output of the following code?
What will be the output of the following code? 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), along with Mermaid knowledge graphs to visualize relationships.
pandas (DataFrames, shape, isna(), value_counts(), iloc, query, dropna, fillna)numpy (Handling np.nan, numerical operations)sklearn (Machine learning models, preprocessing, evaluation)| Operation | Code Example | Output/Use Case |
|---|---|---|
| Shape of DataFrame | df.shape | (rows, columns) |
| Count non-null values | df.shape[0]*df.shape[1] - df.isna().sum().sum() | Total non-missing values |
| Value counts | df['column'].value_counts() | Frequency of unique values |
| Filter rows | df.query("Glucose > 100") | Subset data based on condition |
| Select column by index | df.iloc[:, 4] | Extract a column (e.g., Age) |
| Mean of a column | df['Age'].mean() | Average, ignoring NaN by default |
| Handle missing data | df.dropna() or KNNImputer | Remove or impute missing values |
Handling Missing Data:
df.dropna(): Remove rows/columns with missing values.SimpleImputer or KNNImputer: Fill missing values (e.g., KNNImputer(n_neighbors=3)).Feature Scaling:
Feature Extraction:
DictVectorizer: Converts dictionaries to feature matrices (for structured data).HashingVectorizer: Converts text to fixed-size vectors (not used here).where = mean, = standard deviation.
| Model | Key Parameters | Use Case | Regularization |
|---|---|---|---|
| Linear Regression | - | Regression | None |
| Ridge Regression | alpha (L2 penalty) | Regression with regularization | |
| Lasso Regression | alpha (L1 penalty) | Feature selection | |
| Logistic Regression | C (inverse of alpha), class_weight | Classification | controls regularization |
| Model | Key Parameters | Use Case |
|---|---|---|
| Decision Tree | max_depth, min_samples_split, criterion (gini/entropy for classification, mse for regression) | Classification/Regression |
| Random Forest | n_estimators, bootstrap, max_features | Ensemble learning |
| Gradient Boosting (e.g., XGBoost) | learning_rate, n_estimators | Boosting |
max_depth: Limits tree depth to prevent overfitting.min_samples_split: Minimum samples required to split a node.criterion:
gini (Gini impurity) or entropy.mse (Mean Squared Error).| Algorithm | Key Parameters | Use Case | Key Metrics |
|---|---|---|---|
| K-Means | n_clusters, init (random/k-means++) | Partitional clustering | Inertia, Silhouette Score |
| Agglomerative Clustering | n_clusters, linkage (ward, complete, etc.) | Hierarchical clustering | Dendrogram, Silhouette Score |
where = centroid of cluster .
| Metric | Formula | Use Case |
|---|---|---|
| Accuracy | Classification | |
| Precision | Classification | |
| Recall | Classification | |
| F1-Score | Classification | |
| R² Score | Regression | |
| Confusion Matrix | Table of TP, TN, FP, FN | Classification |
Grid Search: Exhaustive search over specified parameter values. Example:
parameter_grid = {
'n_estimators': [10, 20, 30],
'max_features': [2, 3, 4],
'bootstrap': [True, False]
}
Cross-Validation:
| Method | Key Idea | Key Parameters |
|---|---|---|
| Bagging | Train models on bootstrapped samples, average votes | n_estimators, bootstrap |
| Boosting | Sequentially correct errors from previous models | learning_rate, n_estimators |
| Random Forest | Ensemble of decision trees with feature randomness | max_features, bootstrap |
Data Snooping:
Ordinal vs. Nominal Variables:
Dummy Classifier:
strategy='most_frequent' always predicts the majority class).Perceptron:
tol: Tolerance for stopping criteria.shuffle: Whether to shuffle data before each epoch.| Topic | Equation |
|---|---|
| Standard Scaling | |
| Min-Max Scaling | |
| Ridge (L2) | |
| Lasso (L1) | |
| Logistic Regression | |
| K-Means Inertia | |
| Precision | |
| Recall | |
| F1-Score | |
| R² Score |
shape, isna(), value_counts(), query, iloc, and handling NaN.Sklearn Models:
SGDRegressor uses max_iter for epochs).alpha in Ridge/Lasso vs. C in Logistic Regression (inverse relationship).Evaluation Metrics:
Clustering:
Ensemble Methods:
bootstrap=True by default.Hyperparameter Tuning:
Final Note: Focus on code snippets, parameter interpretations, and mathematical formulas for regression/classification metrics. The Mermaid graphs help visualize relationships between concepts. Good luck!