Upload _2146.py
Browse files
_2146.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
""".2146
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1zrav0p7dTPU_wC5Hee4bqYFrJU2qMRZw
|
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/employment_trends (1).csv'
|
20 |
+
df = pd.read_csv(file_path)
|
21 |
+
|
22 |
+
df.head()
|
23 |
+
|
24 |
+
df['REF_DATE'] = pd.to_datetime(df['REF_DATE'], errors = 'coerce')
|
25 |
+
|
26 |
+
missing_values = df.isnull().sum()
|
27 |
+
missing_values
|
28 |
+
|
29 |
+
sns.histplot(df['VALUE'].dropna(), bins=30, kde=True)
|
30 |
+
plt.title('Distribution of Employment Values')
|
31 |
+
plt.xlabel('Employment Value')
|
32 |
+
plt.ylabel('Frequency')
|
33 |
+
plt.show()
|
34 |
+
|
35 |
+
plt.figure(figsize=(12, 6))
|
36 |
+
sns.countplot(data=df, x='GEO', order=df['GEO'].value_counts().index)
|
37 |
+
plt.xticks(rotation=90)
|
38 |
+
plt.title('Employment Trends by Geography')
|
39 |
+
plt.xlabel('Geography')
|
40 |
+
plt.ylabel('Count')
|
41 |
+
plt.show()
|
42 |
+
|
43 |
+
numeric_df = df.select_dtypes(include=[np.number])
|
44 |
+
plt.figure(figsize=(10, 8))
|
45 |
+
sns.heatmap(numeric_df.corr(), annot=True, cmap='coolwarm', fmt='.2f')
|
46 |
+
plt.title('Correlation Heatmap')
|
47 |
+
plt.show()
|
48 |
+
|
49 |
+
from sklearn.model_selection import train_test_split
|
50 |
+
from sklearn.ensemble import RandomForestRegressor
|
51 |
+
from sklearn.metrics import mean_squared_error
|
52 |
+
|
53 |
+
df_model = df.dropna(subset=['VALUE'])
|
54 |
+
X = df_model[['UOM_ID', 'SCALAR_ID', 'DECIMALS']]
|
55 |
+
y = df_model['VALUE']
|
56 |
+
|
57 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
58 |
+
|
59 |
+
model = RandomForestRegressor(n_estimators=100, random_state=42)
|
60 |
+
model.fit(X_train, y_train)
|
61 |
+
|
62 |
+
y_pred = model.predict(X_test)
|
63 |
+
mse = mean_squared_error(y_test, y_pred)
|
64 |
+
rmse = np.sqrt(mse)
|
65 |
+
rmse
|