WBCHSE HS Artificial Intelligence & Data Science cheat sheet
WBCHSE HS Artificial Intelligence & Data Science · Keep the key ideas within reach.
Introduction to Artificial Intelligence
AI is the engineering of systems that perform tasks associated with human intelligence, including perception, reasoning, learning, decision-making and language.
Key milestones: Turing Test proposed in 1950; Dartmouth workshop in 1956 popularized the term AI; expert systems rose in the 1970s-80s; deep learning resurged in the 2010s.
Conventional computing follows explicitly programmed deterministic rules; AI often learns patterns from data and handles uncertainty, approximation and noisy inputs.
Narrow AI performs a specific task; general AI would transfer across domains; deployed systems today are narrow AI.
An intelligent agent perceives its environment through sensors and acts through actuators; a rational agent maximizes expected performance.
Agent types: simple reflex, model-based reflex, goal-based, utility-based and learning agents.
PEAS specifies an agent by Performance measure, Environment, Actuators and Sensors.
Environment properties: fully or partially observable, deterministic or stochastic, episodic or sequential, static or dynamic, discrete or continuous.
Python Programming for AI and Data Science
Mutable Python objects include list, dict and set; immutable objects include int, float, str and tuple; assigning a mutable object shares its reference.
Control flow: if/elif/else selects branches; for iterates over an iterable; while tests before each iteration; break exits a loop and continue skips to the next iteration.
A function is defined with def name(parameters): and returns a value with return; *args collects positional arguments as a tuple and **kwargs collects keyword arguments as a dict.
List comprehensions use [expr for x in iterable if condition]; indexing is zero-based and slicing a[start:stop:step] excludes stop.
NumPy ndarray stores homogeneous elements; vectorized operations avoid Python loops; shape, dtype, reshape and broadcasting are core array tools.
pandas Series is one-dimensional and labeled; DataFrame is two-dimensional; loc selects by label and iloc by integer position; groupby uses split-apply-combine.
Matplotlib pyplot creates line, scatter, bar and histogram plots; label axes, add a title and legend, then use show() or savefig().
Use try/except/finally for exception handling; with open(...) as f closes the file automatically.
Data Handling, Cleaning and Visualization
Common data sources include CSV, Excel, JSON, SQL databases, APIs and web scraping; data may be structured, semi-structured or unstructured.
Detect missing values with df.isna().sum(); handle them by dropping rows or columns, or by imputing mean, median, mode or a constant, and document the choice.
Detect duplicates with df.duplicated() and remove them with drop_duplicates(); convert types using pd.to_numeric() or pd.to_datetime().
The IQR rule flags values below Q1 - 1.5IQR or above Q3 + 1.5IQR; z-scores beyond about 3 also flag possible outliers; retain or treat them according to context.
Summarize data with describe(), value_counts() and groupby aggregations such as mean, median, count and sum.
Chart choice: line for trends over time, bar for categorical comparison, histogram for distribution, scatter for relationships, boxplot for spread and outliers.
Min-max normalization maps values to [0,1] using (x - min)/(max - min); standardization computes z = (x - mean)/std; fit these statistics on training data only.
Tidy data has one variable per column, one observation per row and one observational unit per table.
Data leakage occurs when test-set or target information enters training; split data before imputation, scaling or feature selection.
Statistics and Probability Foundations
The mean is sensitive to outliers; the median is robust to them; the mode is the most frequent value.
Population variance is sum((xi - mu)^2)/N; sample variance is sum((xi - xbar)^2)/(n - 1); standard deviation is the square root of variance.
IQR = Q3 - Q1; the five-number summary is minimum, Q1, median, Q3 and maximum.
For a normal distribution the 68-95-99.7 rule places about 68% of values within 1 SD, 95% within 2 SD and 99.7% within 3 SD of the mean.
Correlation r lies in [-1, 1], measures linear association only and does not establish causation.
Probability rules: 0 <= P(A) <= 1; P(A') = 1 - P(A); P(A or B) = P(A) + P(B) - P(A and B); independent events satisfy P(A and B) = P(A)P(B).
Conditional probability is P(A|B) = P(A and B)/P(B); Bayes' rule gives P(A|B) = P(B|A)P(A)/P(B).
Sampling methods include simple random, stratified, systematic and cluster; larger samples reduce sampling error, but do not remove bias.
The central limit theorem states that sample means approach a normal distribution as sample size grows, regardless of population shape.
Machine Learning Fundamentals
Supervised learning uses labeled data; unsupervised learning finds structure in unlabeled data; reinforcement learning learns from rewards and penalties.
Regression predicts a continuous target; classification predicts a discrete class; clustering groups similar unlabeled observations.
Split data into training, validation and test sets; fit on training data, tune on validation data and estimate final performance on test data.
Linear regression models y = b0 + b1x1 + ... + bnxn; mean squared error is (1/n)*sum((y - yhat)^2) and is minimized by least squares.
Logistic regression applies a sigmoid to a linear score to output a probability; a threshold such as 0.5 converts probability to class.
k-means chooses k centroids, assigns points to the nearest centroid, recomputes centroids as cluster means and repeats until stable; scale features first.
Confusion matrix terms are TP, TN, FP and FN; accuracy = (TP+TN)/total; precision = TP/(TP+FP); recall = TP/(TP+FN); F1 is their harmonic mean.
Overfitting means high training performance but poor test performance; remedies include more data, simpler models, regularization and cross-validation.
k-fold cross-validation rotates the validation fold k times and averages the scores for a more stable estimate.
Neural Networks and Deep Learning
A perceptron computes a weighted sum plus bias and applies a step activation; it creates a linear boundary and cannot solve XOR alone.
Network layers are input, hidden and output; a dense layer connects every neuron to all neurons in the previous layer.
Activation functions: ReLU = max(0,z); sigmoid = 1/(1+e^-z); tanh outputs [-1,1]; softmax converts scores into multiclass probabilities.
Forward pass: z = Wx + b, then a = f(z); loss measures error, for example cross-entropy for classification or MSE for regression.
Backpropagation applies the chain rule to compute gradients of the loss with respect to weights; optimizers such as SGD or Adam update the weights.
Learning rate too high causes oscillation or divergence; too low makes training slow; an epoch is one pass over training data and batch size is samples per update.
Deep learning stacks many layers to learn hierarchical features; CNNs suit images and RNNs or transformers suit sequences.
Dropout randomly disables neurons during training to reduce overfitting; batch normalization stabilizes and speeds training.
A feedforward network with enough hidden units can approximate continuous functions, but this does not guarantee successful learning from limited data.
Natural Language Processing
Text preprocessing steps include lowercasing, removing punctuation or HTML, tokenization, stopword removal and stemming or lemmatization.
Tokenization splits text into tokens; stemming crudely removes affixes; lemmatization maps words to dictionary base forms using grammar and vocabulary.
Bag-of-words represents a document by token counts and ignores word order, producing sparse vectors.
TF-IDF weights a term by term frequency times inverse document frequency, so terms common across many documents receive lower weight.
Sentiment analysis classifies opinion polarity; approaches include lexicon-based scoring and supervised classifiers; negation and sarcasm remain difficult.
Word embeddings map words to dense vectors so that semantically similar words lie close together; examples include Word2Vec and GloVe.
A chatbot pipeline includes input normalization, intent classification, entity extraction and response selection or generation.
Evaluation uses accuracy, precision, recall and F1; language models may use perplexity; chatbots often require human evaluation.
N-grams capture local word order and are used as count-based features in classical NLP models.
Computer Vision and Image Processing
A digital image is a grid of pixels; grayscale has one channel and RGB has three; an 8-bit pixel value ranges from 0 to 255.
Image tensor shape is height x width x channels; common color spaces include RGB, HSV and grayscale.
Convolution slides a kernel over an image to detect edges, textures and patterns; pooling reduces spatial dimensions.
Classical feature extraction includes edges with Sobel or Canny, corners with Harris and keypoints with SIFT; CNNs learn features automatically.
A CNN typically stacks convolution, ReLU, pooling, flatten and dense layers, with softmax for class probabilities.
Image classification assigns a label to an image; object detection localizes objects with bounding boxes; segmentation labels individual pixels.
Data augmentation uses flips, rotations, crops and color jitter to increase training variation and reduce overfitting.
Evaluation uses accuracy, confusion matrices, precision and recall; intersection over union measures detection or segmentation overlap.
Applications include face recognition, medical imaging, OCR, autonomous vehicles and industrial quality inspection.
AI Ethics, Safety, Privacy and Societal Impact
Bias is systematic unfair error for a group; sources include historical data, sampling, labeling and proxy variables; subgroup metrics help detect it.
Data protection principles include minimum necessary collection, purpose limitation, consent, anonymization or pseudonymization and access control.
Privacy risks include re-identification, inference of sensitive attributes and surveillance; aggregated data can still leak information.
Transparency and explainability require people to know when AI is used and to contest high-stakes decisions; human oversight is often needed.
Accountability assigns responsibility for model outcomes and requires audit trails, documentation and impact assessments.
Automation displaces some tasks while creating new roles; reskilling, social protection and inclusive transition policies matter.
Safety practice includes edge-case testing, monitoring for drift and fail-safe defaults; autonomous systems need explicit risk controls.
Societal risks include misinformation, deepfakes, concentration of power and environmental compute costs; inclusive design can reduce harm.
Fairness metrics include demographic parity and equal opportunity; no single metric satisfies every fairness definition, so choice depends on context.
Practical Work, Project Development and Case Studies
End-to-end pipeline: problem definition, data collection, cleaning, exploratory analysis, feature engineering, modeling, evaluation, deployment and monitoring.
Define a success metric and a simple baseline before modeling; baselines include the majority class or mean target.
Split data before preprocessing to prevent leakage; keep the test set untouched until final evaluation.
Exploratory analysis checks shape, data types, missingness, distributions, correlations and target balance.
Feature engineering includes one-hot or ordinal encoding, scaling, datetime features and text vectorization.
Select models with validation or cross-validation, compare against the baseline and tune hyperparameters.
Error analysis inspects false positives, false negatives, confusion matrices and subgroup performance.
Reports should state data provenance, assumptions, metrics, limitations, ethical risks and reproducibility details such as random seeds and library versions.
Deployment saves the model behind an API, monitors performance and drift, and schedules retraining when needed.