Cheat Sheets & Quick Reference
Linear Regression
\[ \hat{y} = \mathbf{w}^T\mathbf{x} + b \qquad \text{MSE} = \frac{1}{m}\sum_i (\hat{y}_i - y_i)^2 \]
Logistic Regression
\[ \sigma(z) = \frac{1}{1+e^{-z}} \qquad \text{Cross-entropy: } -\sum_i [y_i\log\hat{y}_i + (1-y_i)\log(1-\hat{y}_i)] \]
scikit-learn Pipeline
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
pipe = Pipeline([
("scale", StandardScaler()),
("clf", RandomForestClassifier(n_estimators=100)),
])
pipe.fit(X_train, y_train)
PyTorch Training Loop (minimal)
for epoch in range(epochs):
model.train()
for X_batch, y_batch in loader:
optimizer.zero_grad()
loss = criterion(model(X_batch), y_batch)
loss.backward()
optimizer.step()
Metric Selection Guide
- Balanced classification → F1, ROC-AUC
- Imbalanced, cost of false negatives high → Recall
- Regression with outliers → MAE
- Regression standard → RMSE, R²