This page requires JavaScript to display.
M
Unpacking...
← Data Science & ML
Data Science & ML

Machine & Deep Learning Reference

Regression, classification, clustering, evaluation, and the neural network architectures — condensed from the Machine Learning A-Z and Deep Learning A-Z course material.

Contents
1. Foundations 2. Regression 3. Classification 4. Clustering 5. Model Evaluation 6. Neural Networks 7. CNNs & RNNs 8. Feature Engineering 9. Hyperparameter Tuning 10. Imbalanced Data 11. Model Deployment

1. Foundations

2. Regression

ModelNotes
Linear RegressionFits a straight-line relationship; interpretable coefficients, assumes linearity.
Polynomial RegressionLinear regression on polynomial features — captures curvature, risks overfitting at high degree.
Ridge / LassoAdd L2 / L1 penalties to reduce overfitting; Lasso can zero out weak features.
Decision Tree / Random Forest RegressorSplits feature space into regions; forests average many trees to cut variance.
Support Vector RegressionFits within an error margin (epsilon tube); kernel trick handles non-linearity.
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = LinearRegression().fit(X_train, y_train)
predictions = model.predict(X_test)

3. Classification

from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report

clf = RandomForestClassifier(n_estimators=200, random_state=42)
clf.fit(X_train, y_train)
print(classification_report(y_test, clf.predict(X_test)))

4. Clustering

5. Model Evaluation

TaskMetrics
RegressionMAE, MSE, RMSE, R²
ClassificationAccuracy, precision, recall, F1, ROC-AUC, confusion matrix
Cross-validationk-fold CV to estimate generalization and reduce variance from a single split

Watch for the bias–variance trade-off: an underfit model has high bias (too simple), an overfit model has high variance (memorizes training noise).

6. Neural Networks (ANN)

A network of layered neurons: each neuron computes a weighted sum of inputs plus a bias, then applies a non-linear activation (ReLU, sigmoid, tanh). Training uses forward propagation to predict, a loss function to score error, and backpropagation with gradient descent (or Adam) to update weights.

from tensorflow import keras

model = keras.Sequential([
    keras.layers.Dense(64, activation="relu", input_shape=(n_features,)),
    keras.layers.Dense(32, activation="relu"),
    keras.layers.Dense(1, activation="sigmoid")
])
model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
model.fit(X_train, y_train, epochs=50, batch_size=32, validation_split=0.2)

7. CNNs & RNNs

8. Feature Engineering

from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline

preprocess = ColumnTransformer([
    ("num", StandardScaler(), ["age", "income"]),
    ("cat", OneHotEncoder(handle_unknown="ignore"), ["region"])
])
pipe = Pipeline([("prep", preprocess), ("model", RandomForestClassifier())])
pipe.fit(X_train, y_train)

9. Hyperparameter Tuning

MethodNotes
Grid searchExhaustively tries every combination in a defined grid — thorough, expensive as parameters grow
Random searchSamples random combinations — often finds a near-optimal result far cheaper than a full grid
Bayesian optimizationUses prior trial results to choose the next combination intelligently — fewest trials for a given quality
from sklearn.model_selection import GridSearchCV

param_grid = {"n_estimators": [100, 200, 400], "max_depth": [None, 10, 20]}
search = GridSearchCV(RandomForestClassifier(), param_grid, cv=5, scoring="f1")
search.fit(X_train, y_train)
print(search.best_params_, search.best_score_)

10. Imbalanced Data

When one class dominates (fraud detection, rare disease), accuracy stops being meaningful — a model predicting the majority class every time can still score 99%.

11. Model Deployment

import joblib

joblib.dump(pipe, "model.joblib")
loaded = joblib.load("model.joblib")
loaded.predict(new_data)