Machine Learning Notes
Contents
- Algorithms
- Bayes
- Explainability
- MLOps
- Model Evaluation
- Preprocessing
- Reinforcement Learning
- SQL
- Statistics
Algorithms
- K-means: aims to choose centroids that minimize the inertia, or within-cluster sum-of-squares criterion. Use the “elbow” method to identify the right number of means. scikit tutorial
- KNN: Simple, flexible, naturally handles multiple classes. Slow at scale, sensitive to feature scaling and irrelevant features. scikit tutorial
- Linear Discriminant Analysis (LDA): A classifier with a linear decision boundary, generated by fitting class conditional densities to the data and using Bayes’ rule. The model fits a Gaussian density to each class, assuming that all classes share the same covariance matrix. scikit tutorial
- Linear regression
- assumptions (LINE) source
- Linearity
- Independence of errors
- Normality of errors
- Equal variances
- Tests of assumptions: i) plot each feature on x-axis vs y_error, ii) plot y_predicted on x-axis vs y_error, iii) histogram of errors.
- Overspecified model can be used for prediction of the label, but should not be used to ascribe the effect of a feature on the label.
- Linear algebra solution
- assumptions (LINE) source
- Naive Bayes: uses naive conditional independence assumption of features. scikit
- PCA: transform data using k vectors that minimize the perpendicular distance to points. PCA can be also thought of as an eigenvalue/engenvector decomposition. scikit. Intuition paper
- Pearson’s correlation coefficient**. wiki.
- Random Forests: each tree is built using a sample of rows (with replacement) from training set. Less prone to overfitting. scikit
- RNN: Karpathy tutorial
- Sorting tutorial.
- Stochastic gradient descent tutorial. Calculus solution:
- SVD: Singular Value Decomposition intuition with PCA use case
- SVM: Effective in high dimensional spaces (or when number of dimensions > number of examples). SVMs do not directly provide probability estimates. scikit
- Transformers tutorial
Bayes
- Nature article overview
- Bayesian A/B Testing in PyMC3
- Inference — Intuition and Example (Beta & Binomial)
Explainability
- Books: Interpretable Machine Learning
- Tutorials: twosigma: a brief survey
- EthicalML tools EthicalML github
- Partial dependence plots (PDP): x-axis = value of a single feature, y-axis = label. scikit
- Individual conditional expectation (ICE): x-axis = value of a single feature, y-axis = label. scikit
- Permutation feature importance: Randomly shuffle features and calculate impact on model metrics such as F1. scikit
- Global surrogate: train an easily interpretable model (such as liner regression) on the predictions made by a black box model
- Local Surrogate: LIME (for Local Interpretable Model-agnostic Explanations). Train individual models to approximate an individual prediction by removing features to learn their impact on the prediction
- Shapley Value (SHAP): The contribution of each feature is measured by adding and removing it from all other feature subsets. The Shapley Value for one feature is the weighted sum of all its contributions
MLOps
- BentoML: open platform that simplifies ML model deployment by saving models in a standard format, defining a web service with pre/post processing, deploying the web service in a container
- Data a16z
- ML Blueprint a16z
- Lifecycle AWS blog
- EthicalML/awesome-production-machine-learning EthicalML github
- Pipeline tools EthicalML/data-pipeline-etl-frameworks
- MLOps Google Google
Model evaluation
- Classification:
- Regression
- R2: strength of a linear relationship. Could be 0 for nonlinear relationships. Never worsens with more features. scikit
- Learning curves scikit tutorial
- Overfitting and regularization
- Overfitting (high variance) options: more data, increase regularization, or decrease model complexity. tutorial
- Underfitting (high bias) options: decrease regularization, increase model complexity
- Lasso regression: linear model regularization technique with tendency to prefer solutions with fewer non-zero coefficients. scikit tutorial.
- Ridge regression: imposes a penalty on the size of the coefficients scikit
- Validation curve: scikit
Preprocessing
- scikit
- Analysis
- Remove duplicates
- SOCS of each feature: Shape (skew), Outliers, Center, Spread
- Feature correlation
- Production pipeline
- Outliers: remove or apply non-linear transformations
- Missing values
- SMOTE: Generate and place a new point on the vector between a minority class point and one of its nearest neighbors, located [0, 1] percent of the way from the original point. Algorithm is parameterized with k_neighbors. tutorial
- Standardization
- Discretization
- Encoding categorical features
- Generating polynomial features
- Dimensionality reduction
Reinforcement Learning
SQL
- window functions, row_number() and partition(): tutorial
- COALESCE(): evaluates the arguments in order and returns the current value of the first expression that initially doesn’t evaluate to NULL. tutorial
Statistics
- Statology tutorial
- Means
- Arithmetic: wolfram
- Geometric: used in finance to calculate average growth rates and is referred to as the compounded annual growth rate. wolfram
- Harmonic: used in finance to average multiples like the price-earnings ratio because it gives equal weight to each data point. Using a weighted arithmetic mean to average these ratios would give greater weight to high data points than low data points because price-earnings ratios aren't price-normalized while the earnings are equalized. wolfram
- Probability distributions Description acronym SOCS: shape, outliers, center, spread. Comparison article.
- Beta: probability distribution on probabilities bounded [0, 1]. tutorial
- Binomial: probability of obtaining k successes in n binomial experiments with probability p. tutorial
- Normal: empirical rule is sometimes called the 68-95-99.7 rule
- Poisson: the probability of obtaining k successes during a given time interval. Statology tutorial. tutorial 2.Zero Inflated Poisson Regression Model
- Sample variance: divided by n-1 to achieve an unbiased estimator because 1 degree of freedom is used to estimate b0. tutorial
- Tests
- ANOVA: Analysis of variance compares the means of three or more independent groups to determine if there is a statistically significant difference between the corresponding population means. Statology tutorial
- F-statistic: determines whether to reject a full model (F) in favor of a reduced (R) model. Reject full model if F is large — or equivalently if its associated p-value is small. tutorial
- Linear regression coefficient CI: tutorial
- T-test: tutorial