Upload _1952.py
Browse files
_1952.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
""".1952
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colab.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1Gw-RJg5Bp__ayBzDb0HsHaj9uYYfQ_nI
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
# Commented out IPython magic to ensure Python compatibility.
|
| 11 |
+
import pandas as pd
|
| 12 |
+
import numpy as np
|
| 13 |
+
import seaborn as sns
|
| 14 |
+
import matplotlib.pyplot as plt
|
| 15 |
+
import warnings
|
| 16 |
+
warnings.filterwarnings('ignore')
|
| 17 |
+
# %matplotlib inline
|
| 18 |
+
|
| 19 |
+
file_path = '/content/Key_Economic_Indicators.csv'
|
| 20 |
+
df = pd.read_csv(file_path)
|
| 21 |
+
|
| 22 |
+
df.head()
|
| 23 |
+
|
| 24 |
+
df.isnull().sum()
|
| 25 |
+
|
| 26 |
+
df.fillna(df.mean(), inplace=True)
|
| 27 |
+
|
| 28 |
+
df['Date'] = pd.to_datetime(df[['Year', 'Month']].assign(DAY=1))
|
| 29 |
+
|
| 30 |
+
df.drop(['Year', 'Month'], axis=1, inplace=True)
|
| 31 |
+
|
| 32 |
+
df.head()
|
| 33 |
+
|
| 34 |
+
plt.figure(figsize=(12, 6))
|
| 35 |
+
sns.lineplot(data=df, x='Date', y='Consumer Confidence Index TX', label='TX')
|
| 36 |
+
plt.title('Consumer Confidence Index Over Time')
|
| 37 |
+
plt.xlabel('Date')
|
| 38 |
+
plt.ylabel('Consumer Confidence Index')
|
| 39 |
+
plt.legend()
|
| 40 |
+
plt.show()
|
| 41 |
+
|
| 42 |
+
plt.figure(figsize=(12, 6))
|
| 43 |
+
sns.histplot(df['Unemployment TX'], kde=True, color='blue', label='TX')
|
| 44 |
+
sns.histplot(df['Unemployment U.S.'], kde=True, color='red', label='US')
|
| 45 |
+
plt.title('Distribution of Unemployment Rates')
|
| 46 |
+
plt.xlabel('Unemployment Rate')
|
| 47 |
+
plt.ylabel('Frequency')
|
| 48 |
+
plt.legend()
|
| 49 |
+
plt.show()
|
| 50 |
+
|
| 51 |
+
numeric_df = df.select_dtypes(include=[np.number])
|
| 52 |
+
|
| 53 |
+
plt.figure(figsize=(14, 10))
|
| 54 |
+
sns.heatmap(numeric_df.corr(), annot=True, fmt='.2f', cmap='coolwarm')
|
| 55 |
+
plt.title('Correlation Matrix of Economic Indicators')
|
| 56 |
+
plt.show()
|
| 57 |
+
|
| 58 |
+
from sklearn.model_selection import train_test_split
|
| 59 |
+
from sklearn.ensemble import RandomForestRegressor
|
| 60 |
+
from sklearn.metrics import mean_squared_error
|
| 61 |
+
|
| 62 |
+
X = numeric_df.drop(columns=['Consumer Confidence Index TX'])
|
| 63 |
+
y = numeric_df['Consumer Confidence Index TX']
|
| 64 |
+
|
| 65 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 66 |
+
|
| 67 |
+
model = RandomForestRegressor(random_state=42)
|
| 68 |
+
model.fit(X_train, y_train)
|
| 69 |
+
|
| 70 |
+
y_pred = model.predict(X_test)
|
| 71 |
+
|
| 72 |
+
mse = mean_squared_error(y_test, y_pred)
|
| 73 |
+
rmse = np.sqrt(mse)
|
| 74 |
+
rmse
|