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 the core topics, concepts, and equations essential for the Diploma Level: Machine Learning Practice (Computer-Based Exam). The summary is organized by key themes, followed by a Mermaid knowledge graph to visualize relationships between topics.
Handling Missing Data
df.dropna(thresh=N): Drops rows with fewer than N non-NaN values.df.fillna(value): Fills missing values with a specified value.df.dropna(thresh=45) drops rows with >5 missing values (for 50 features).Feature Scaling
StandardScaler: Standardizes features to have mean=0 and variance=1.
scaler.mean_ returns the mean of each feature before scaling.MinMaxScaler: Scales features to a range (default: [0, 1]).
scaler.data_max_ returns the max value of each feature.Encoding Categorical Data
OneHotEncoder: Converts categorical features into binary vectors.
['cat', 'dog'] → [[1, 0], [0, 1]].(n_samples, n_categories).PolynomialFeatures: Generates polynomial/combination features.
degree=2 for [a, b] → [1, a, b, a², ab, b²].(n_samples, 1 + n_features + C(n_features, 2) + ... ).Feature Selection
VarianceThreshold: Removes low-variance features.
VarianceThreshold(threshold=0.1) removes features with variance < 0.1.Linear Models
LinearRegression:
fit_intercept=True: Includes a bias term (intercept).fit_intercept=False: Forces the model through the origin.R²): Higher for fit_intercept=True if data has an intercept.SGDRegressor:
learning_rate='constant': Fixed learning rate (eta0).partial_fit: Updates model incrementally (useful for large datasets).squared_loss, huber, epsilon_insensitive.Tree-Based Models
DecisionTreeClassifier:
Hyperparameters:
max_depth: Maximum depth of the tree.min_samples_split: Minimum samples required to split a node.criterion: gini (default) or entropy.Attributes:
max_depth: Actual depth of the trained tree.feature_importances_: Importance of each feature.RandomForestClassifier:
max_features: Number of features to consider for splits (lower → higher variance).n_estimators: Number of trees in the forest.Ensemble Methods
BaggingClassifier:
max_samples: Number of samples to draw for each base estimator (default: full dataset).bootstrap: Whether to sample with replacement.AdaBoostClassifier:
n_estimators, learning_rate.GradientBoostingClassifier:
n_estimators, learning_rate, max_depth.Neural Networks
MLPClassifier/MLPRegressor:
hidden_layer_sizes: Tuple specifying neurons per layer (e.g., (5, 3) → 2 layers).alpha: L2 regularization strength (higher → stronger regularization).partial_fit: Incremental learning (requires warm_start=True for repeated fits).Clustering
KMeans:
n_clusters, init (e.g., k-means++), max_iter.Evaluation:
n_clusters to find the "elbow."Silhouette Score: Measures cluster cohesion/separation (higher = better).
Metrics
Regression:
Classification:
Cross-Validation
k folds (no stratification).Learning Curves
log_loss over epochs for SGDClassifier.Chunking:
pd.read_csv(chunksize=N): Reads file in chunks of N rows.SGDRegressor.partial_fit.Incremental Learning:
partial_fit: SGDClassifier, GaussianNB, PassiveAggressiveClassifier.StandardScaler.VarianceThreshold or model-based importance (e.g., feature_importances_ in trees).| Concept | Equation |
|---|---|
| Standard Scaling | |
| MinMax Scaling | |
| R² Score | |
| MSE | |
| Log Loss | |
| Silhouette Score | |
| Decision Tree Leaf Nodes | (balanced binary tree) |
Pandas/NumPy:
df.dropna, df.fillna, df.query, and aggregation methods (mean, median, value_counts).df[df['Salary'] > 50000] or df.loc[df['Salary'] > 50000].Scikit-Learn:
Commands:
fit, transform, fit_transform.predict vs. predict_proba.Hyperparameters:
n_estimators, learning_rate, alpha (regularization).Attributes:
coef_, intercept_, feature_importances_, labels_ (clustering).Mathematics:
fit_intercept affects linear models.Algorithms:
max_depth and min_samples_split affect overfitting.max_samples in BaggingClassifier).alpha (regularization) and hidden_layer_sizes.Evaluation:
GridSearchCV).Large Data:
chunksize with pd.read_csv and partial_fit for incremental learning.Clustering:
n_clusters (Elbow Method, Silhouette Score).