AI & Machine Learning Cheat Sheet
Free AI & Machine Learning cheat sheet: the most-used AI & Machine Learning syntax and methods at a glance — searchable and beginner-friendly.
Key Concepts
| Concept | Syntax | Example |
|---|---|---|
| Supervised learning | Labeled data → model | Classification, Regression |
| Unsupervised learning | Unlabeled data → patterns | Clustering, Dimensionality reduction |
| Reinforcement learning | Agent → actions → rewards | Game AI, Robotics |
| Transfer learning | Pre-trained model → fine-tune | Use BERT for your NLP task |
Common Algorithms
| Concept | Syntax | Example |
|---|---|---|
| Linear Regression | y = wx + b | Predicting house prices |
| Decision Tree | if-else rules from data | Customer churn prediction |
| K-Nearest Neighbors | Classify by nearest points | Image classification |
| Neural Network | Layers of weighted nodes | Deep learning, NLP |
| Random Forest | Ensemble of decision trees | Robust classification/regression |
Python for ML
| Concept | Syntax | Example |
|---|---|---|
| NumPy array | np.array([1, 2, 3]) | import numpy as np |
| Pandas DataFrame | pd.DataFrame(data) | df = pd.read_csv('data.csv') |
| Train/test split | train_test_split(X, y) | from sklearn.model_selection import train_test_split |
| Fit model | model.fit(X_train, y_train) | model = LinearRegression(); model.fit(X, y) |
Data Preparation
| Concept | Syntax | Example |
|---|---|---|
| Normalization | (x - min) / (max - min) | Scale features to 0-1 range |
| Standardization | (x - mean) / std | Scale features to mean=0, std=1 |
| One-hot encoding | pd.get_dummies(df['col']) | Convert categories to binary columns |
| Handle missing | df.fillna() / df.dropna() | df['col'].fillna(df['col'].mean()) |
Evaluation Metrics
| Concept | Syntax | Example |
|---|---|---|
| Accuracy | (TP+TN) / Total | Overall correctness |
| Precision | TP / (TP+FP) | Of predicted positive, how many correct? |
| Recall | TP / (TP+FN) | Of actual positive, how many found? |
| F1 Score | 2 * (P*R) / (P+R) | Harmonic mean of precision & recall |