CS5720 - Week 1
Slide 17 of 20

Setting Up Your First Neural Network

1
Environment Setup
Essential
Install Python, essential libraries, and development tools. Get your workspace ready for neural network development.
pip install tensorflow numpy pandas matplotlib
2
Data Preparation
Critical
Load, explore, and preprocess your dataset. Split into training and testing sets for proper evaluation.
X_train, X_test, y_train, y_test = train_test_split(...)
3
Define Architecture
Design
Choose number of layers, neurons, and activation functions. Start simple and iterate based on performance.
model = Sequential([Dense(128, activation='relu'), ...])
4
Compile Model
Configuration
Select optimizer, loss function, and metrics. These choices significantly impact training performance.
model.compile(optimizer='adam', loss='mse', metrics=['mae'])
5
Train & Evaluate
Execute
Fit the model to training data and monitor performance. Use validation data to tune hyperparameters.
history = model.fit(X_train, y_train, validation_split=0.2)

🚀 Quick Start Demo

💻 Live Code Editor
import tensorflow as tf from tensorflow import keras import numpy as np # Generate sample data X = np.random.random((1000, 10)) y = np.random.random((1000, 1)) # Build model model = keras.Sequential([ keras.layers.Dense(64, activation='relu'), keras.layers.Dense(32, activation='relu'), keras.layers.Dense(1, activation='linear') ]) # Compile model.compile(optimizer='adam', loss='mse', metrics=['mae']) # Train history = model.fit(X, y, epochs=50, validation_split=0.2, verbose=0) print(f"Final loss: {history.history['loss'][-1]:.4f}")
📊 Training Progress
Epoch: 0/50 Loss: --
Install TensorFlow
Get TensorFlow 2.x installed and verify GPU support if available
Load Sample Data
Import a simple dataset like MNIST or create synthetic data
Build First Model
Create a simple 2-3 layer neural network with ReLU activations
Train & Validate
Fit the model and monitor training/validation loss curves
Make Predictions
Use trained model to make predictions on new data
Visualize Results
Plot training curves and analyze model performance

🏗️ Interactive Network Builder

Input Size
Hidden Layers
Neurons per Layer
Output Size
Prepared by Dr. Gorkem Kar