File size: 1,966 Bytes
b09b46b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- coding: utf-8 -*-
""".1952

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1Gw-RJg5Bp__ayBzDb0HsHaj9uYYfQ_nI
"""

# Commented out IPython magic to ensure Python compatibility.
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
# %matplotlib inline

file_path = '/content/Key_Economic_Indicators.csv'
df = pd.read_csv(file_path)

df.head()

df.isnull().sum()

df.fillna(df.mean(), inplace=True)

df['Date'] = pd.to_datetime(df[['Year', 'Month']].assign(DAY=1))

df.drop(['Year', 'Month'], axis=1, inplace=True)

df.head()

plt.figure(figsize=(12, 6))
sns.lineplot(data=df, x='Date', y='Consumer Confidence Index TX', label='TX')
plt.title('Consumer Confidence Index Over Time')
plt.xlabel('Date')
plt.ylabel('Consumer Confidence Index')
plt.legend()
plt.show()

plt.figure(figsize=(12, 6))
sns.histplot(df['Unemployment TX'], kde=True, color='blue', label='TX')
sns.histplot(df['Unemployment U.S.'], kde=True, color='red', label='US')
plt.title('Distribution of Unemployment Rates')
plt.xlabel('Unemployment Rate')
plt.ylabel('Frequency')
plt.legend()
plt.show()

numeric_df = df.select_dtypes(include=[np.number])

plt.figure(figsize=(14, 10))
sns.heatmap(numeric_df.corr(), annot=True, fmt='.2f', cmap='coolwarm')
plt.title('Correlation Matrix of Economic Indicators')
plt.show()

from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error

X = numeric_df.drop(columns=['Consumer Confidence Index TX'])
y = numeric_df['Consumer Confidence Index TX']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

model = RandomForestRegressor(random_state=42)
model.fit(X_train, y_train)

y_pred = model.predict(X_test)

mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
rmse