Home / Past papers / MLP End Term / this paper














What does the following code return?






Consider the following code:

















What will be the output of the following code?
What will be the output of the following code?





















Consider the following code:




























What will be the output of the following code snippet?


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.
Handling Missing Data
df.dropna(thresh=N): Drops rows with fewer than N non-NaN values.df.fillna(value): Fills missing values.Feature Scaling
StandardScaler: Standardizes features (mean=0, std=1).
MinMaxScaler: Scales features to a range (default: [0, 1]).
Encoding Categorical Data
OneHotEncoder: Converts categorical features into binary columns.
['cat', 'dog'] → [[1, 0], [0, 1]].['cat', 'dog'] → [0, 1]).Polynomial Features
PolynomialFeatures(degree=N): Generates polynomial combinations up to degree N.
X = [a, b] → [1, a, b, a², ab, b²] for degree=2.| Task | Command |
|---|---|
| Compute mean of a column | df['column'].mean() |
| Filter rows | df[df['Salary'] > 50000] |
| Count values in a column | df['Department'].value_counts()['HR'] |
| Sort by a column | df.sort_values(by='Score', ascending=False) |
| Select top row after sorting | df.sort_values(...).iloc[0] |
Linear Regression
SGDRegressor:
learning_rate='constant': Keeps learning rate fixed (eta0).partial_fit(X, y): Incremental learning (useful for large datasets).partial_fit for online learning.Parameters:
max_depth: Maximum depth of the tree.min_samples_split: Minimum samples required to split a node.criterion: 'gini' (Gini impurity) or 'entropy' (information gain).Attributes:
tree_.max_depth: Actual depth of the tree.feature_importances_: Importance of each feature.max_depth=3 → leaf nodes.Random Forest
max_features: Number of features to consider for splits (lower → higher variance).n_estimators: Number of trees in the forest.Gradient Boosting (GradientBoostingClassifier)
n_estimators: Number of boosting stages.learning_rate: Shrinks contribution of each tree.Bagging (BaggingClassifier)
max_samples: Number of samples to draw for each base estimator (default: 1.0 = all samples).MLPClassifier/MLPRegressor)Parameters:
hidden_layer_sizes: Tuple specifying neurons per layer (e.g., (5, 3) = 2 layers with 5 and 3 neurons).alpha: L2 regularization strength (higher → less overfitting).max_iter: Maximum epochs.Effect of alpha:
alpha → stronger regularization → simpler model.Metrics:
Regression:
Classification:
Cross-Validation:
KFold: Splits data into k folds.StratifiedKFold: Preserves class distribution in folds.Learning Curves:
Parameters:
n_clusters: Number of clusters (k).init: Initialization method ('k-means++' or 'random').max_iter: Maximum iterations.Evaluation:
k.a: Mean distance to points in the same cluster.b: Mean distance to points in the nearest other cluster.PCA (Principal Component Analysis):
n_components: Number of principal components to keep.GridSearchCV)cv: Number of cross-validation folds.scoring: Metric to optimize (e.g., 'accuracy', 'neg_mean_squared_error').RandomizedSearchCV)n_iter).Models Supporting partial_fit:
SGDClassifier, SGDRegressorGaussianNBPassiveAggressiveClassifierUse Case: Large datasets that don’t fit in memory.
Example:
for chunk in pd.read_csv("large_file.csv", chunksize=1000):
model.partial_fit(chunk[X_cols], chunk[y_col])VarianceThreshold:
VarianceThreshold(threshold=0.1).| Concept | Equation |
|---|---|
| Linear Regression | |
| Logistic Regression | |
| MSE | |
| R² Score | |
| Standard Scaling | |
| MinMax Scaling | |
| Log Loss | |
| Silhouette Score | |
| Gini Impurity | |
| Entropy |
Pandas/NumPy:
df[df['Salary'] > 50000]), sort (sort_values), and aggregate (groupby, mean).dropna and fillna.Scikit-Learn:
fit, predict, transform, fit_transform, score.partial_fit (e.g., SGDClassifier, GaussianNB).Decision Trees:
max_depth, min_samples_split, and criterion affect the tree.Evaluation Metrics:
Clustering:
k.n_clusters.Hyperparameter Tuning:
GridSearchCV vs. RandomizedSearchCV: trade-off between exhaustiveness and efficiency.Neural Networks:
hidden_layer_sizes=(5, 3) means 2 hidden layers with 5 and 3 neurons.alpha controls regularization (higher = less overfitting).