Think about you’re operating an e-commerce web site and also you wish to construct a mannequin that predicts whether or not an individual will purchase a product primarily based on three options:
- Age
- Revenue
- Procuring habits (how typically they purchase merchandise)
You resolve to construct a easy neural community to do that, which is able to predict whether or not somebody will make a purchase order or not (1 for “Sure” and 0 for “No”).
Right here’s how your community is about up:
- Enter Layer: Takes in 3 options — age, earnings, buying habits.
- Hidden Layer 1: 4 neurons (this layer will course of the knowledge and extract options).
- Hidden Layer 2: 2 neurons (this layer additional processes the knowledge).
- Output Layer: 1 neuron (that is the place the ultimate prediction is made — both 0 or 1).
from tensorflow.keras.fashions import Sequential
from tensorflow.keras.layers import Dense# Outline the mannequin
mannequin = Sequential([
Dense(4, input_dim=3, activation='relu'), # First hidden layer with 4 neurons
Dense(2, activation='relu'), # Second hidden layer with 2 neurons
Dense(1, activation='sigmoid') # Output layer with 1 neuron (binary classification)
])
# Show the mannequin abstract
mannequin.abstract()
Working mannequin.abstract()
would offer you an output that appears like this:
Layer (kind) Output Form Param #
=================================================================
input_1 (InputLayer) (None, 3) 0
_________________________________________________________________
dense (Dense) (None, 4) 16
_________________________________________________________________
dense_1 (Dense) (None, 2) 10
_________________________________________________________________
dense_2 (Dense) (None, 1) 3
=================================================================
Whole params: 29
Trainable params: 29
Non-trainable params: 0