0% found this document useful (0 votes)
2 views20 pages

Predicting Economic Recessions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views20 pages

Predicting Economic Recessions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Predicting Economic Recessions

Using LSTM Neural Networks


Recession Analysis
• A Recession is an economic situation that
arrives when the circulation of money in the
economy is low for two consecutive quarters.
• When the circulation of money is low, it means
people are not spending money in the market.
• When people don’t spend money, businesses
face losses, which results in an economic
slowdown and layoffs, which we have already
heard about in 2023.
Agenda
• The agenda of a recession analysis involves
systematically examining the causes,
characteristics, and effects of a recession.
• Typically with the goal of understanding its impact
on the economy and developing strategies to
mitigate future downturns.
• This helps in systematically understanding a
recession’s causes and consequences while offering
actionable insights for recovery and future
resilience
Methodologies

Data Preprocessing
Time Series Sequence Creation
Train-Test Split
LSTM Model Architecture
Project Overview
• The primary goal of this project is to develop a
machine learning model using Long Short-Term
Memory (LSTM) neural networks to predict economic
recessions based on key economic indicators such as
GDP, Unemployment Rate, and Inflation.
• This project leverages time series forecasting
techniques to capture patterns and trends in
historical economic data, enabling the model to
forecast future recessions.
Objectives
• Identify the Causes of the Recession
• Assess the Economic Impact
• Understand the Social and Employment Effects
• Provide Forecasts and Future Outlook
Execution
• Importing Libraries:

import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense

• numpy and pandas for handling data.


• MinMaxScaler for normalizing the features.
• Sequential, LSTM, and Dense from Keras to build and train
the LSTM model
• Loading the Dataset:

data = pd.read_csv('economic_data.csv')

• Loads the dataset containing economic


indicators (GDP, Unemployment, Inflation) and
the target variable (Recession) into a
DataFrame.
Dataset: “ economic_data.csv “
• Selecting Features and Target

features = data[['GDP', 'Unemployment', 'Inflation']]


target = data['Recession'] # 1 if recession, 0 if no recession

• Selects input features (GDP, Unemployment,


Inflation) and the target variable (Recession)
for prediction.
• Scaling the Data

scaler = MinMaxScaler() scaled_features =


scaler.fit_transform(features)

• Normalizes the features to a range between 0


and 1, which helps improve the LSTM model's
training performance.
• Creating Time Series Sequences:

def create_sequences(data, target, time_steps=10):


X, y = [], []
for i in range(len(data) - time_steps):
X.append(data[i:i + time_steps])
y.append(target[i + time_steps])
return np.array(X), np.array(y)

• Defines a function to generate time series


sequences. Each sequence contains 10 consecutive
data points, which the model will use to predict the
next step (recession).
• Generate Sequences for LSTM:

time_steps = 10
X, y = create_sequences
(scaled_features, target, time_steps)

• Generates the input sequences (X) and labels


(y) from the scaled features for time series
forecasting using a 10-step window.
• Splitting the Data into Train and Test Sets:

train_size = int(0.8 * len(X))


X_train, X_test = X[:train_size], X[train_size:]
y_train, y_test = y[:train_size], y[train_size:]

• Splits the data into training (80%) and testing


(20%) sets to evaluate the model's
performance.
• Building the LSTM Model:

model = Sequential()
model.add(LSTM(units=50, return_sequences=True,
input_shape=(time_steps, X_train.shape[2])))
model.add(LSTM(units=50))
model.add(Dense(1, activation='sigmoid'))

• Defines a sequential LSTM model:


• First LSTM layer with 50 units and return_sequences=True (to
pass output to the next LSTM layer).
• Second LSTM layer with 50 units.
• Final Dense layer with 1 neuron and sigmoid activation for
binary classification.
• Compiling the Model:

model.compile(optimizer='adam',
loss='binary_crossentropy', metrics=['accuracy'])

• Compiles the model using:


• Adam optimizer: Efficient for gradient-based
optimization.
• Binary cross-entropy loss: Suitable for binary
classification (recession or not).
• Accuracy: As a metric to evaluate performance.
• Training the Model:

model.fit(X_train, y_train, epochs=20, batch_size=32,


validation_split=0.2)

• Trains the LSTM model for 20 epochs, with a


batch size of 32, using 20% of the training data
as validation.
• Evaluating the Model:

loss, accuracy = model.evaluate(X_test, y_test)


print(f"Test Accuracy: {accuracy * 100:.2f}%")

• Evaluates the model on the test set and prints


the accuracy.
Results
• Performance: The model achieved a good
balance between training and testing
accuracy, indicating it effectively learned
patterns in the economic data.

• Training Accuracy
• Test Accuracy
• Validation Loss
Links
• Recessions are periods of economic
contraction having a significant impact on
various industries.

• Explore the dataset and code


Click here to access the GitHub repository
Thank You!

You might also like