First Neural Network with TensorFlow
Basic implementation using TensorFlow.
First Neural Network with TensorFlow is a free Learn AI with Python lesson on CoddyKit — lesson 5 of 5. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 5 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Building Your First Neural Network with TensorFlow
In this lesson, we will create a simple feedforward neural network using TensorFlow. TensorFlow is a popular framework for building and training machine learning models.

2
Step 1: Setting Up TensorFlow
First, ensure that TensorFlow is installed. If not, you can install it using:
pip install tensorflow
We’ll also import the required libraries for this lesson.
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import numpy as np3
Step 2: Preparing the Dataset
For this example, we’ll use a simple dataset where the input is a single feature, and the output is its double:
# Generate sample data
X = np.array([[1], [2], [3], [4], [5]], dtype=float)
y = np.array([[2], [4], [6], [8], [10]], dtype=float)4
Step 3: Creating the Model
We’ll create a simple model with one input layer, one hidden layer, and one output layer. The hidden layer will use the ReLU activation function.
# Create the model
model = Sequential([
Dense(10, activation='relu', input_shape=(1,)), # Hidden layer with 10 neurons
Dense(1) # Output layer with 1 neuron
])5
Step 4: Compiling the Model
We compile the model with:
- Loss Function: Mean Squared Error for regression tasks.
- Optimizer: Stochastic Gradient Descent (SGD).
# Compile the model
model.compile(optimizer='sgd', loss='mean_squared_error')6
Step 5: Training the Model
We train the model using the training data for 500 epochs. During training, the model learns to minimize the loss.
# Train the model
model.fit(X, y, epochs=500, verbose=1)7
Step 6: Making Predictions
After training, we can use the model to make predictions on new data:
# Predict on new data
print(model.predict([6]))8
Step 7: Evaluating the Model
We evaluate the model’s performance on the training data to ensure it has learned the pattern correctly:
# Evaluate the model
loss = model.evaluate(X, y)
print(f"Loss: {loss}")9
Real-World Applications
Feedforward neural networks built using TensorFlow can be applied to:
- Predictive Analytics: Forecasting sales and trends.
- Classification: Spam detection, fraud detection.
- Regression: Price prediction, demand forecasting.
10
Summary and Next Steps
In this lesson, we:
- Built and trained a simple neural network using TensorFlow.
- Learned about the key steps: dataset preparation, model creation, compilation, and training.
- Made predictions and evaluated the model’s performance.
Next, we’ll explore how neural networks are extended to more advanced architectures like convolutional neural networks (CNNs) for image processing tasks.

Frequently asked questions
Is the “First Neural Network with TensorFlow” lesson free?
Yes — the full text of “First Neural Network with TensorFlow” is free to read here on the web, and the Learn AI with Python course includes 5 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.
What will I learn in “First Neural Network with TensorFlow”?
Basic implementation using TensorFlow. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Learn AI with Python?
No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 5 of 5, so you can start here or from the beginning and move at your own pace.
How long does the “First Neural Network with TensorFlow” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Learn AI with Python lesson?
Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Introduction to Neural Networks
- Activation Functions
- Feedforward Neural Networks
- Backpropagation Algorithm
- First Neural Network with TensorFlow