Home / Past papers / MLP End Term / this paper
Consider the following Python code using Pandas: What does the groupby operation in the code achieve?































Consider a dataset representing various attributes of red wine, loaded into a Pandas DataFrame named data using the following code: Suppose we are interested in extracting the value of the chlorides attribute for the third sample in the dataset (2nd by index). Which of the following expressions correctly achieves this? chlorides is at the 4th index of columns.



















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 summary is organized by domains (e.g., Data Preprocessing, Supervised Learning, Unsupervised Learning, Model Evaluation, etc.), followed by key equations (where applicable) and Mermaid knowledge graphs to visualize relationships.
Handling Missing Data
SimpleImputer (mean/median/mode imputation).si.statistics_ returns the mean/median of each column.Feature Scaling
Why scale?
Categorical Encoding
One-Hot Encoding: Converts categorical variables into binary columns.
Car_color → Black, Blue, Red (binary columns).Feature Selection
SelectKBest(chi2, k=3) selects the 3 best features based on chi-squared scores.Linear Models
Logistic Regression:
Loss: Log loss (cross-entropy).
Effect of α: Higher α → more penalty on large coefficients (prevents overfitting).
Support Vector Machines (SVM)
Linear SVM:
Kernel Trick:
linear, poly, rbf, sigmoid.Decision Trees
Splitting Criteria:
Hyperparameters:
max_depth: Maximum depth of the tree.min_samples_split: Minimum samples required to split a node.min_samples_leaf: Minimum samples required at a leaf node.max_depth or min_samples_leaf.Neural Networks (MLP)
Architecture:
Activation Functions:
relu, tanh, logistic.Output layer:
identity.logistic.softmax.Regularization (α):
Stochastic Gradient Descent (SGD)
Loss Functions:
hinge: SVM.log_loss: Logistic regression.squared_error: Linear regression.Penalties:
l1 (Lasso), l2 (Ridge), elasticnet.Key Parameters:
learning_rate: Step size for updates.max_iter: Maximum epochs.warm_start: Reuse previous solution for incremental learning.Clustering
K-Means:
Elbow Method: Plot inertia vs. k to find optimal clusters.
Dimensionality Reduction
PCA (Principal Component Analysis):
Evaluation Metrics
Classification:
Regression:
Cross-Validation
Hyperparameter Tuning
Example:
param_grid = {'C': [0.1, 1, 10], 'kernel': ['linear', 'rbf']}
grid_search = GridSearchCV(SVC(), param_grid, cv=5)Bias-Variance Tradeoff
Bagging (Bootstrap Aggregating)
Boosting
Voting Classifier
| Scenario | Recommended Approach |
|---|---|
| Large dataset (1000+ GB) | SGDClassifier (incremental learning) |
| Non-linear decision boundary | Kernel SVM or Neural Networks |
| High-dimensional data | Ridge Regression or PCA + Linear Model |
| Imbalanced classes | Adjust class weights or use SMOTE |
| Feature importance needed | Random Forest or Lasso Regression |
| Clustering similar items | K-Means (if spherical clusters) or DBSCAN |
| Concept | Equation |
|---|---|
| Standard Scaling | |
| MinMax Scaling | |
| Logistic Regression | |
| Ridge Regression | |
| Lasso Regression | |
| K-Means Inertia | |
| R² Score | |
| RMSE | |
| Gini Impurity | |
| Entropy | |
| MLP Parameters (1 hidden) |
Pandas Operations:
groupby().mean() → Calculates average per group.df.iloc[row, col] → Access by integer position.df['column'][index] → Access column by name and row by index.Scikit-Learn Syntax:
fit() → Train the model.predict() → Generate predictions.predict_proba() → Class probabilities (for classifiers).score() → Returns accuracy (for classifiers) or R² (for regressors).Common Pitfalls:
alpha in Ridge/Lasso (higher α = stronger regularization).min_samples_split and min_samples_leaf in decision trees.Key Takeaways:
coef_ (linear models) or feature_importances_ (tree-based models).| Topic | Key Points |
|---|---|
| StandardScaler | Mean=0, Std=1; use for distance-based models. |
| Ridge vs. Lasso | Ridge: L2 (shrinks coefficients); Lasso: L1 (can zero coefficients). |
| SGDClassifier | Use loss='hinge' for SVM, loss='log_loss' for logistic regression. |
| K-Means | Elbow method to choose k; inertia = within-cluster sum of squares. |
| Decision Trees | max_depth controls complexity; deeper trees risk overfitting. |
| Neural Networks | hidden_layer_sizes=(10,) for 1 hidden layer with 10 neurons. |
| Cross-Validation | cv=5 in GridSearchCV → 5-fold cross-validation. |
| Voting Classifier | voting='soft' for probability averaging; 'hard' for majority class. |
| Imbalanced Data | Use class_weight='balanced' or SMOTE. |
| PCA | Reduces dimensions; first component = max variance direction. |