Evolve AI Institute

Neural Networks Quick Reference Card

Lesson 4: Introduction to Neural Networks

Lesson 4 Cheat Sheet

๐Ÿง  Neural Network Basics

Architecture Components

INPUT โ†’ [WEIGHTS] โ†’ HIDDEN โ†’ [WEIGHTS] โ†’ OUTPUT
  (4)      (W1)       (10)       (W2)        (3)

Input Layer: Receives raw data (size = # features)

Hidden Layer: Extracts patterns (size = flexible)

Output Layer: Makes predictions (size = # classes)

๐Ÿ”ข Key Formulas

Weighted Sum

z = (xโ‚ ร— wโ‚) + (xโ‚‚ ร— wโ‚‚) + ... + (xโ‚™ ร— wโ‚™) + bias

Matrix Form

z = X ยท W + b

Activation Functions

ReLU (Hidden Layers):

f(x) = max(0, x)

Sigmoid:

f(x) = 1 / (1 + e^(-x))

Softmax (Output Layer):

f(xแตข) = e^(xแตข) / ฮฃ(e^(xโฑผ))

Loss Function

Loss = -ฮฃ(y_true ร— log(y_pred))

Gradient Descent

weight_new = weight_old - learning_rate ร— gradient

๐Ÿ’ป Essential Code Snippets

Load Data

from sklearn.datasets import load_iris
iris = load_iris()
X, y = iris.data, iris.target

Split Data

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
)

Scale Features

from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

One-Hot Encode Labels

from sklearn.preprocessing import OneHotEncoder
encoder = OneHotEncoder(sparse_output=False)
y_train_enc = encoder.fit_transform(y_train.reshape(-1, 1))

Initialize Weights

import numpy as np
W1 = np.random.randn(input_size, hidden_size) * 0.01
b1 = np.zeros((1, hidden_size))

Forward Pass

z1 = np.dot(X, W1) + b1
a1 = relu(z1)
z2 = np.dot(a1, W2) + b2
a2 = softmax(z2)

Calculate Loss

loss = -np.sum(y_true * np.log(a2 + 1e-8)) / m

Update Weights

W1 -= learning_rate * dW1
b1 -= learning_rate * db1

๐Ÿ“Š Training Process

The Training Loop

  1. Forward Propagation: Input โ†’ Hidden โ†’ Output
  2. Calculate Loss: Compare prediction to actual
  3. Backward Propagation: Compute gradients
  4. Update Weights: Apply gradient descent
  5. Repeat for all epochs

Checking Progress

# During training, monitor:
print(f"Epoch {epoch}: Loss={loss:.4f}, Acc={acc:.4f}")

# Plot after training:
plt.plot(losses)
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.show()

๐ŸŽ›๏ธ Hyperparameters Guide

Common Values

ParameterTypical RangeGood Starting Point
Learning Rate0.001 - 0.10.01 or 0.1
Hidden Neurons10 - 10010-20 for Iris
Epochs100 - 2000500-1000
Batch Size16 - 12832

Tuning Tips

Learning Rate:

Hidden Neurons:

Epochs:

๐Ÿ› Common Errors & Fixes

"Shape mismatch"

# Check dimensions
print(X.shape, W.shape)
# Ensure: (samples, features) ร— (features, neurons)

"Loss is NaN"

# Clip values to prevent overflow
np.clip(x, -500, 500)
# Or reduce learning rate

"All predictions same class"

# Check weights initialized (not zeros)
# Verify learning rate not too small
# Ensure sufficient training epochs

"Accuracy not improving"

# Try different learning rate
# Add more hidden neurons
# Train for more epochs
# Check data is normalized

๐Ÿ“ˆ Evaluation Metrics

Accuracy

from sklearn.metrics import accuracy_score
acc = accuracy_score(y_true, y_pred)

Confusion Matrix

from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_true, y_pred)

Visual Check

# Plot predictions vs actual
plt.scatter(range(len(y_test)), y_test, label='Actual')
plt.scatter(range(len(y_pred)), y_pred, label='Predicted')
plt.legend()

๐Ÿ” Debugging Checklist

Before asking for help, check:

๐Ÿ’ก Quick Tips

Best Practices

DO:

DON'T:

๐ŸŽฏ Architecture Patterns

Classification (Iris)

Input(4) โ†’ Hidden(10) โ†’ Output(3)
         ReLU         Softmax

Digits Recognition

Input(64) โ†’ Hidden(50) โ†’ Output(10)
          ReLU          Softmax

Binary Classification

Input(n) โ†’ Hidden(20) โ†’ Output(1)
         ReLU          Sigmoid

Deep Network

Input โ†’ Hidden1 โ†’ Hidden2 โ†’ Hidden3 โ†’ Output
        ReLU      ReLU      ReLU      Softmax

๐Ÿ“š Key Terminology

Epoch: One complete pass through training data

Batch: Subset of data processed at once

Learning Rate (ฮท): Step size for weight updates

Loss: Measure of prediction error

Gradient: Direction to adjust weights

Activation: Non-linear transformation function

Overfitting: Memorizing training data

Underfitting: Failing to learn patterns

Backpropagation: Algorithm to compute gradients

Forward Pass: Computing predictions

Backward Pass: Computing gradients

๐Ÿš€ Next Steps

After mastering basics:

  1. Convolutional Neural Networks (CNNs)
  2. For image processing
  3. Learn filters and convolution
  1. Recurrent Neural Networks (RNNs)
  2. For sequential data
  3. Time series, text
  1. Deep Learning Frameworks
  2. TensorFlow/Keras
  3. PyTorch
  1. Advanced Topics
  2. Transfer learning
  3. GANs
  4. Transformers

๐Ÿ†˜ Need Help?

During Class:

Outside Class:

๐Ÿ”— Useful Links

Visualizations:

Tutorials:

Documentation:

Print this card and keep it handy during labs!

Evolve AI Institute

Free AI Education for All

info@evolveaiinstitute.com | www.evolveaiinstitute.com