Home / Formulas / MLP
MLP formula sheet
Collected automatically from the lessons. Print it, or read it the night before.
Week 1 - Your first end-to-end ML project
- RMSE =n1∑(y−y^)2; MAE =n1∑∣y−y^∣
- Standardise σx−μ; min-max max−minx−min
train_test_split(X, y, test_size=0.25, random_state=..., stratify=y)SimpleImputer(strategy="mean"|"median"|"most_frequent"|"constant"); learned statistics_OneHotEncoder(handle_unknown="ignore"), OrdinalEncoder(), LabelEncoder() (targets)
Week 2 - The project continued: pipelines and tuning
- Fits =combinations×cv(+1); list-of-dict grids add combinations
- RMSE from negated MSE scores:
np.sqrt(-scores) Pipeline([(name, step), ...]), make_pipeline(...); tune with "step__param"ColumnTransformer([(name, transformer, columns)], remainder="drop"|"passthrough")cross_val_score(est, X, y, cv=5, scoring=...); LeaveOneOut(); KFold(n_splits=k)
Week 3 - Linear regression and gradient descent in sklearn
- MSE cost J=n1∥Xw−y∥2; gradient n2XT(Xw−y)
invscaling: η=eta0/tpower_t; adaptive: divide by 5 when stalled; constant: η=eta0SGDRegressor defaults: squared_error, l2, alpha=1e-4, max_iter=1000, tol=1e-3, invscaling, eta0=0.01, power_t=0.25SGDClassifier defaults: hinge, learning_rate="optimal"
Week 4 - Polynomial regression and regularisation
- Polynomial feature count: (dn+d) (with bias), minus 1 without
- Ridge: ∥y−Xw∥2+α∥w∥2; w=(XTX+αI)−1XTy
- Lasso (sklearn): 2n1∥y−Xw∥2+α∥w∥1
- Defaults:
alpha=1.0 (Ridge, Lasso, ElasticNet), l1_ratio=0.5 (ElasticNet) - More regularisation:
alpha ↑; C ↓
Week 5 - Logistic regression in sklearn
- σ(z)=1+e−z1; softmax pk=∑ezjezk
- Log loss −n1∑[ylnp+(1−y)ln(1−p)]
predict_proba →(m,K); decision_function →(m,) binary, (m,K) multi-class; coef_ →(1,d) or (K,d)
Week 6 - Binary classifiers and how to judge them
- accuracy =nTP+TN; precision =TP+FPTP; recall (TPR) =TP+FNTP; specificity =TN+FPTN; FPR =FP+TNFP
- F1=P+R2PR
confusion_matrix(y_true, y_pred) =[[TN,FP],[FN,TP]]precision_recall_curve, roc_curve, roc_auc_score, classification_report
Week 7 - Multiclass classifiers
- OvR classifiers =K; OvO classifiers =2K(K−1) (10 classes: 10 vs 45)
precision_score(y, pred, average="macro"|"weighted"|"micro")confusion_matrix(y_true, y_pred): rows = true, columns = predicted
Week 8 - SVMs in sklearn
- Poly kernel (γ⟨x,x′⟩+coef0)degree; RBF e−γ∥x−x′∥2;
gamma="scale" =1/(nfeatVar(X)) - Margin =2/∥w∥
- Defaults:
SVC(C=1, kernel="rbf", degree=3, gamma="scale", coef0=0); LinearSVC(C=1, penalty="l2", loss="squared_hinge"); SVR(epsilon=0.1)
Week 9 - Decision trees and ensembles
- Gini =1−∑pk2; entropy =−∑pklog2pk; cost =mmLGL+mmRGR
- Defaults: tree
criterion="gini", max_depth=None, min_samples_leaf=1; BaggingClassifier(n_estimators=10, bootstrap=True); RandomForestClassifier(n_estimators=100, max_features="sqrt") - OOB fraction ≈0.37 per tree;
oob_score=True → oob_score_
Week 10 - Random forests, boosting and tuning
- AdaBoost (sklearn, 2 classes): αt=ηlnεt1−εt; textbook 21lnεt1−εt
- Gradient boosting: Fm=Fm−1+ηhm(residuals)
- Fits =∏(list lengths)×cv;
range(a, b, step) excludes b
Week 11 - Neural networks in sklearn
- Parameters: ∑ℓ(mℓnℓ+nℓ) over layers;
n_layers_ = input + hidden + output - Defaults:
hidden_layer_sizes=(100,), activation="relu", solver="adam", alpha=1e-4, learning_rate_init=1e-3, max_iter=200, tol=1e-4, n_iter_no_change=10
Week 12 - Unsupervised learning in sklearn
- Inertia =∑i∥xi−μzi∥2; silhouette in [−1,1]
- DBSCAN defaults
eps=0.5, min_samples=5; noise label −1 - GMM parameters (full): K(d+2d(d+1))+K−1; BIC =−2lnL+plnn (lower is better)
- PCA: variance explained =∑≤kλ/∑λ; reconstruction error =∑>kλ