← Back to Tutorials Chapter 20

References

This final chapter serves as a quick reference for the most important ML algorithms, Python libraries, and their APIs. Bookmark this page for easy access during your ML development work.

ML Reference — Key Algorithms

When to Use Each Algorithm

Linear Regression: Continuous target, linear relationship, interpretability needed.
Logistic Regression: Binary classification, probabilistic output, baseline model.
Decision Trees: Interpretable, non-linear relationships, categorical features.
Random Forest: High accuracy, handles missing data, less interpretable.
SVM: High-dimensional data, clear margin of separation, small datasets.
KNN: Low-dimensional data, non-parametric, no training phase needed.
Naive Bayes: Text classification, fast training, independence assumption holds.
K-Means: Spherical clusters, large datasets, known number of clusters.
DBSCAN: Arbitrary-shaped clusters, outlier detection, unknown cluster count.
PCA: Dimensionality reduction, visualization, decorrelate features.
XGBoost: Structured/tabular data, competitions, when performance matters most.

Libraries Reference

NumPy

Fundamental for numerical computing. Provides N-dimensional arrays, linear algebra operations, random number generation, and Fast Fourier Transforms.

import numpy as np

# Array creation
arr = np.array([1, 2, 3, 4, 5])
zeros = np.zeros((3, 4))
ones = np.ones((2, 3))
range_arr = np.arange(0, 10, 2)
linspace = np.linspace(0, 1, 5)

# Operations
arr_2d = np.random.randn(3, 4)
print(f"Shape: {arr_2d.shape}")
print(f"Mean: {arr_2d.mean():.3f}")
print(f"Std:  {arr_2d.std():.3f}")

# Linear algebra
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
C = A @ B  # matrix multiplication
print(f"Matrix product:\n{C}")

Pandas

Data manipulation and analysis library. Provides DataFrame and Series structures for handling structured data with intuitive operations.

import pandas as pd

# Creating a DataFrame
df = pd.DataFrame({
    'name': ['Alice', 'Bob', 'Charlie'],
    'age': [25, 30, 35],
    'salary': [50000, 60000, 70000]
})

# Common operations
print(df.head())
print(df.describe())
print(df.groupby('age').mean())
print(df.sort_values('salary', ascending=False))

# Handling missing values
# df.dropna(inplace=True)
# df.fillna(df.mean(), inplace=True)

Scikit-learn

The go-to library for classical ML. Provides consistent APIs across models, preprocessing utilities, model selection tools, and evaluation metrics.

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report
from sklearn.pipeline import Pipeline

# Pipeline example
pipeline = Pipeline([
    ('scaler', StandardScaler()),
    ('classifier', LogisticRegression())
])

# X_train, X_test, y_train, y_test = train_test_split(X, y)
# pipeline.fit(X_train, y_train)
# y_pred = pipeline.predict(X_test)
# print(classification_report(y_test, y_pred))

TensorFlow

End-to-end deep learning framework by Google. Keras is its high-level API for building and training neural networks. Supports eager execution and production deployment via TensorFlow Serving.

PyTorch

Deep learning framework by Meta (Facebook). Known for its dynamic computation graph, Pythonic design, and strong ecosystem (TorchVision, TorchText, TorchAudio). Preferred in research and increasingly in production.

import torch
import torch.nn as nn

# Simple neural network in PyTorch
class SimpleNet(nn.Module):
    def __init__(self, input_size, hidden_size, num_classes):
        super().__init__()
        self.layer1 = nn.Linear(input_size, hidden_size)
        self.relu = nn.ReLU()
        self.layer2 = nn.Linear(hidden_size, num_classes)

    def forward(self, x):
        x = self.layer1(x)
        x = self.relu(x)
        x = self.layer2(x)
        return x

# model = SimpleNet(784, 128, 10)
# criterion = nn.CrossEntropyLoss()
# optimizer = torch.optim.Adam(model.parameters(), lr=0.001)

API Reference — Common Functions & Parameters

train_test_split(X, y, test_size=0.2, random_state=42)
StandardScaler().fit_transform(X) — standardize features to mean=0, std=1.
LabelEncoder().fit_transform(y) — encode categorical labels as integers.
OneHotEncoder(drop='first').fit_transform(X) — one-hot encode categories.
cross_val_score(model, X, y, cv=5) — perform k-fold cross-validation.
GridSearchCV(model, param_grid, cv=5) — exhaustive hyperparameter search.
confusion_matrix(y_true, y_pred) — generate confusion matrix.
classification_report(y_true, y_pred) — precision, recall, f1 per class.

Further Reading

Books: "Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow" by Géron, "The Elements of Statistical Learning" by Hastie et al., "Pattern Recognition and Machine Learning" by Bishop.
Courses: Stanford CS229, MIT 6.036, fast.ai Practical Deep Learning.
Documentation: scikit-learn docs, PyTorch docs, TensorFlow docs.
Papers: arXiv.org (cs.LG), NeurIPS, ICML, ICLR proceedings.

ML reference sheet
Note: ML is a rapidly evolving field. Stay updated by following conferences, reading papers, and practicing regularly. The tools change, but the fundamental concepts — bias-variance tradeoff, gradient descent, regularization — remain relevant.
Congratulations! You have completed all 20 chapters of this ML tutorial. Keep building, keep learning, and remember: the best model is the one that solves the problem effectively and ethically.
Final Challenge: Combine everything you have learned. Find a real-world dataset (e.g., from Kaggle or UCI ML Repository). Perform exploratory data analysis, preprocess the data, train and compare at least three different models, tune hyperparameters, evaluate with appropriate metrics, and present your findings in a short report. Deploy the best model as a web API.