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

ConceptSyntaxExample
Supervised learningLabeled data → modelClassification, Regression
Unsupervised learningUnlabeled data → patternsClustering, Dimensionality reduction
Reinforcement learningAgent → actions → rewardsGame AI, Robotics
Transfer learningPre-trained model → fine-tuneUse BERT for your NLP task

Common Algorithms

ConceptSyntaxExample
Linear Regressiony = wx + bPredicting house prices
Decision Treeif-else rules from dataCustomer churn prediction
K-Nearest NeighborsClassify by nearest pointsImage classification
Neural NetworkLayers of weighted nodesDeep learning, NLP
Random ForestEnsemble of decision treesRobust classification/regression

Python for ML

ConceptSyntaxExample
NumPy arraynp.array([1, 2, 3])import numpy as np
Pandas DataFramepd.DataFrame(data)df = pd.read_csv('data.csv')
Train/test splittrain_test_split(X, y)from sklearn.model_selection import train_test_split
Fit modelmodel.fit(X_train, y_train)model = LinearRegression(); model.fit(X, y)

Data Preparation

ConceptSyntaxExample
Normalization(x - min) / (max - min)Scale features to 0-1 range
Standardization(x - mean) / stdScale features to mean=0, std=1
One-hot encodingpd.get_dummies(df['col'])Convert categories to binary columns
Handle missingdf.fillna() / df.dropna()df['col'].fillna(df['col'].mean())

Evaluation Metrics

ConceptSyntaxExample
Accuracy(TP+TN) / TotalOverall correctness
PrecisionTP / (TP+FP)Of predicted positive, how many correct?
RecallTP / (TP+FN)Of actual positive, how many found?
F1 Score2 * (P*R) / (P+R)Harmonic mean of precision & recall