Home / Past papers / MLP End Term / this paper











































































Use the confusion matrix given below. What is the recall score for the label (class) 1 ?











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 exam, followed by Mermaid knowledge graphs to visualize relationships.
Scaling/Normalization:
MinMaxScaler: Scales features to [0, 1] range. Formula:StandardScaler: Standardizes features to mean=0, std=1. Formula:Encoding Categorical Data:
OneHotEncoder: Converts categorical features into binary columns.LabelEncoder: Converts categorical labels into integers (e.g., ['Yes', 'No'] → [1, 0]).Polynomial Features:
PolynomialFeatures(degree=n): Generates interaction terms up to degree n. Example: For features [a, b], degree=2 generates [1, a, b, a², ab, b²].Pipelines:
Pipeline([('scaler', StandardScaler()), ('model', SGDRegressor())]): Chains preprocessing and modeling steps.sparse=True in OneHotEncoder for memory efficiency.Linear Regression:
Ridge (L2) vs. Lasso (L1) Regression:
SGDRegressor:
Key parameters:
learning_rate='adaptive' (adjusts learning rate dynamically).penalty='l2' (Ridge), alpha=0.01 (regularization strength).multi_class='multinomial' with solver='lbfgs'.Distance Metrics:
Hyperparameters:
n_neighbors: Trade-off between bias (small k) and variance (large k).weights='distance': Closer neighbors have more influence.Kernel Trick: Maps data to higher dimensions for linear separation.
C controls margin width (small C → wider margin, more regularization).SVC vs. SVR:
SVC: Classification (hinge loss).SVR: Regression (ε-insensitive loss).Decision Tree:
Overfitting Risk: Prune with max_depth or min_samples_split.
bootstrap=True).max_features='sqrt' (classification) or 'auto' (regression).OOB Score: Out-of-bag error estimate (oob_score=True).
Hyperparameters:
n_estimators: Number of weak learners.learning_rate: Shrinks contribution of each learner (default=1.0).n_estimators or learning_rate.Architecture:
Key Parameters:
hidden_layer_sizes=(100,): Single hidden layer with 100 neurons.activation='relu': Fast convergence, avoids vanishing gradients.solver='adam': Adaptive learning rate.early_stopping=True: Stops training if validation score doesn’t improve.StandardScaler).| Metric | Formula | Use Case |
|---|---|---|
| Accuracy | Balanced datasets. | |
| Precision | Minimize false positives. | |
| Recall (Sensitivity) | Minimize false negatives. | |
| F1-Score | Imbalanced datasets. | |
| ROC-AUC | Area under ROC curve (TPR vs. FPR). | Binary classification. |
| MSE/RMSE | Regression. |
Predicted
| 0 | 1 |
-----------|-------|-------|
Actual 0 | TN | FP |
Actual 1 | FN | TP |
Solutions:
class_weight='balanced').K-Means:
Hyperparameters:
n_clusters: Number of clusters (use elbow method).init='k-means++': Better initialization than random.Scaling: Required (uses Euclidean distance).
Linkage Methods:
PCA (Principal Component Analysis):
n_components to retain ≥95% variance.Key Parameters:
cv=5: 5-fold cross-validation.n_iter=10: Number of random samples (for RandomizedSearchCV).param_dist = {'ridge__alpha': [0.01, 0.1, 1, 10, 100]}
search = RandomizedSearchCV(pipeline, param_distributions=param_dist, cv=5)
Overfitting:
Solutions:
max_depth).Underfitting:
Solutions:
model.feature_importances_ (tree-based) or coefficients (linear models).| Task | Class/Method | Example |
|---|---|---|
| Train-test split | train_test_split | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) |
| Cross-validation | cross_val_score | scores = cross_val_score(model, X, y, cv=5) |
| Dummy models | DummyClassifier(strategy='median') | Baseline comparison. |
| Target type detection | type_of_target | type_of_target(y) → 'multiclass' |
| Classification report | classification_report | print(classification_report(y_true, y_pred)) |
fit vs. transform:
fit: Learns parameters (e.g., mean/std for scaling).transform: Applies learned parameters.