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

Learn it in a lesson: Introduction to AI & ML · Advanced NLP: Transformers, BERT, T5, LLaMA, Mistral

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

Learn it in a lesson: Decision Trees & Random Forests · Linear Regression · Final AI Project — Build & Deploy a Full End-to-End ML System · Neural Networks Introduction

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)

Learn it in a lesson: Python for Machine Learning

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())

Learn it in a lesson: Data Preprocessing

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

Learn it in a lesson: Classification Basics

Working with Data

ConceptSyntaxExample
Load a CSVpd.read_csv(path)df = pd.read_csv('sales.csv')
First look
Do this before any modelling. Most bad models start with unread data.
df.head() / df.info() / df.describe()df.info() # columns, types, how many are missing
Missing values
Fill using the TRAINING set's median only, or you leak information into the test set.
df.isna().sum() / df.fillna()df['age'] = df['age'].fillna(df['age'].median())
Encode categories
Never feed raw text labels to a numeric model.
pd.get_dummies | OneHotEncoderX = pd.get_dummies(df, columns=['city'])
Scale features
Fit on train, transform on test. Fitting on both is the classic leak.
StandardScaler()X = StandardScaler().fit_transform(X)

Learn it in a lesson: Data Preprocessing · Pandas: Inspecting Data: head, tail, info, describe

Training & Evaluation

ConceptSyntaxExample
Split
Set random_state so the split is the same next time.
train_test_split(X, y, test_size=.2, random_state=0)X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=.2, random_state=0)
Fit and predict.fit(X, y) / .predict(X)model.fit(X_tr, y_tr); preds = model.predict(X_te)
Cross-validation
One split can flatter a model by luck. Five tells you more.
cross_val_score(model, X, y, cv=5)cross_val_score(model, X, y, cv=5).mean()
Confusion matrix
Shows WHICH errors you make, which accuracy hides entirely.
confusion_matrix(y_true, y_pred)confusion_matrix(y_te, preds)
Overfitting
The model memorised. Simplify it, regularise it, or get more data.
train score >> test score1.00 on train, 0.71 on test
Class imbalance
With 99% negatives, a model that always says no scores 99% and is useless.
class_weight='balanced'LogisticRegression(class_weight='balanced')

Learn it in a lesson: Evaluating AI Models: F1, ROC, Perplexity, BLEU, WER · Python for Machine Learning · Handling Imbalanced Data

LLMs & Prompting

ConceptSyntaxExample
Temperature
Lower is more repeatable, not more correct.
temperature: 0-20 for extraction, 0.7 for drafting
Token
Both cost and context limits are counted in tokens, not words.
a chunk of text, roughly 4 characters of English"unbelievable" is 3-4 tokens
Embeddingtext to vectorcosine similarity compares meaning, not spelling
RAG
Grounds an answer in your data instead of the model's memory.
retrieve, then generateSearch your documents, put the hits in the prompt
Hallucination
Ask for sources you can check, then check them.
confident and wrongAn invented citation that looks perfectly real

Learn it in a lesson: Large Language Models Architecture (GPT, LLaMA, Mistral) · Building Retrieval-Augmented Generation (RAG) Systems