Machine learning and Neural networks are being used to solve complex problems - from recognizing images to predicting stock prices. How a computer can "learn" patterns from historical data and make predictions, neural networks are the answer.
We will cover the base concepts that are crucial before diving into stock price prediction using neural networks.
Neural Network
A neural network (NN) is a computational model inspired by the human brain. It consists of layers of neurons that process input data to produce an output.
Structure of a Neural Network
Input Layer: Takes in the features of your data (e.g., stock prices, volume, etc.)
Hidden Layers: Perform computations to learn patterns
Output Layer: Produces the prediction or result
Each neuron in a layer is connected to neurons in the next layer through weights, which control the influence of each input on the output.
To predict we need to know two terms weights and activation function, with these two we can make the prediction.
Weights and Biases: How a Neural Network Learns
Weights
Think of weights as importance scores for each input.
The network multiplies each input by its corresponding weight.
During training, the network adjusts these weights to reduce prediction errors.
Bias
Bias allows the neuron to shift the output, similar to adding a constant in linear equations.
It helps the network fit data better, especially when all inputs are zero.
Now let's understand this with an example,
Example Scenario
You want to decide if you should carry an umbrella today.
Let's take today's weather data for this example, and let's predict whether we should carry an umbrella today.
![Screenshot 2025-10-05 124202]()
So, based on the above data, we have plotted the table. Since there is no mention of Rain forecast and Sunny forecast, we are taking it as 0.
Feature | Value |
---|
Rain forecast (x1) | 0 (not explicitly mentioned, so assume no rain) |
Sunny forecast (x2) | 0 (cloudy, so not sunny) |
Cloud coverage (x3) | 91 (%) |
Humidity (x4) | 84 (%) |
Wind speed (x5) | 18 km/h |
Assign Weights
Feature | Weight | Reason |
---|
Rain forecast (x1) | +3 | Most important for umbrella decision |
Sunny forecast (x2) | -2 | Sunny weather reduces the likelihood |
Cloud coverage (x3) | +0.1 | Slightly increases the chance if very cloudy |
Humidity (x4) | +0.05 | High humidity slightly increases the chance |
Wind speed (x5) | -0.05 | High wind slightly reduces chance |
Bias | -5 | Sets baseline threshold for carrying umbrella |
So you can ask on what basis we have given the weight?
To predict rain forecast -> X1, that is, the Rain forecast is very important, so we have given a highly positive number.
X2 -> If it is too sunny, the chance of rain is less, right? So we have given -2.
x3 -> Cloud coverage increases the chance of rain, so +0.1 and so on.
So the weight is calculated in the below formula,
z=x1​w1​+x2​w2​+x3​w3​+x4​w4​+x5​w5​+b
z=(0∗3)+(0∗−2)+(91∗0.1)+(84∗0.05)+(18∗−0.05)+(−5)
z=0+0+9.1+4.2−0.9−5
z=7.4, so weight is 7.4
Now let's see what an activation function,
Activation Functions: Making the Network Non-Linear
Without activation functions, neural networks would just be a series of linear equations. Activation functions introduce non-linearity, allowing the network to learn complex patterns.
Common Activation Functions
Sigmoid: Outputs 0 → 1, used for probabilities
Tanh: Outputs -1 → 1, centered at 0
ReLU (Rectified Linear Unit): Outputs 0 → ∞, very popular in hidden layers
Linear: Outputs the same as the input, used in regression tasks like predicting prices
Now let's calculate the activation function (sigmoid),
The activation function is calculated using the following formula,
output = 1 / (1+e^-z)
output = 1 / ( 1 + e ^ -0.74)
~ 1 / ( 1 + 0.00061)
~ 0.9994
Output ≈ 0.9994, which is very close to 1, meaning the neuron "decides" carry the umbrella.
Interpretation
Cloud coverage (91%) → positive weight pushes output up
Humidity (84%) → slightly increases output
Wind speed (18 km/h) → slight negative effect
No rain or sun → rain not contributing, sun not reducing output
Bias (-5) → sets threshold so neuron doesn't fire unless conditions are significant
Even with no rain, the neuron predicts carrying an umbrella because high cloud coverage and humidity combined are strong enough.
So this is how neural networks work. In the next article, let's deep dive into stock prediction with the example written in Python, along with its related concepts like time series, etc.
In the meantime, if you have any doubts about the above, drop yours in the comments. I will answer it.