Aksel Joonas Reedi commited on
Commit
2ac2216
2 Parent(s): 6bd7feb cb3748e

Merge branch 'aksel'

Browse files
past_weather_data.csv CHANGED
@@ -15,4 +15,5 @@ date,temp,humidity,precip,windspeed,sealevelpressure,visibility,solarradiation
15
  2023-10-30,11.2,90.4,13.0,18.4,997.5,28.8,27.0
16
  2023-10-31,11.0,93.7,18.6,18.0,1000.7,17.9,29.8
17
  2023-11-01,12.4,88.5,4.9,25.9,997.8,32.6,31.5
18
- 2023-11-02,11,80,8.7,46.4,976.4,33.6,21.5
 
 
15
  2023-10-30,11.2,90.4,13.0,18.4,997.5,28.8,27.0
16
  2023-10-31,11.0,93.7,18.6,18.0,1000.7,17.9,29.8
17
  2023-11-01,12.4,88.5,4.9,25.9,997.8,32.6,31.5
18
+ 2023-11-02,11.0,80.0,8.7,46.4,976.4,33.6,21.5
19
+ 2023-11-03,9.6,83.3,7.9,32.4,981.6,31,40.1
pollution_data.csv CHANGED
@@ -12,4 +12,5 @@ date,NO2,O3
12
  2024-10-27,27.53722134983982,20.80809239842384
13
  2024-10-28,23.337567567567568,26.82861788617886
14
  2024-10-29,16.53533209586906,23.28254887605004
15
- 2024-10-30,22.26162162162162,18.03443548387097
 
 
12
  2024-10-27,27.53722134983982,20.80809239842384
13
  2024-10-28,23.337567567567568,26.82861788617886
14
  2024-10-29,16.53533209586906,23.28254887605004
15
+ 2024-10-30,22.26162162162162,18.03443548387097
16
+ 2024-10-31,24.919333333333334,20.79696
predictions_history.csv CHANGED
@@ -70,3 +70,9 @@ NO2,2024-10-30,2024-10-31,29.77507241979599
70
  O3,2024-10-30,2024-11-01,21.135906183680472
71
  NO2,2024-10-30,2024-11-01,28.38872595850704
72
  O3,2024-10-30,2024-11-02,19.67426015042635
 
 
 
 
 
 
 
70
  O3,2024-10-30,2024-11-01,21.135906183680472
71
  NO2,2024-10-30,2024-11-01,28.38872595850704
72
  O3,2024-10-30,2024-11-02,19.67426015042635
73
+ O3,2024-10-31,2024-11-01,16.491393851863755
74
+ NO2,2024-10-31,2024-11-01,17.22825222459993
75
+ O3,2024-10-31,2024-11-02,16.874728806873033
76
+ NO2,2024-10-31,2024-11-02,14.771381333796965
77
+ O3,2024-10-31,2024-11-03,15.244292496093546
78
+ NO2,2024-10-31,2024-11-03,14.606430068166452
src/predict.py CHANGED
@@ -3,9 +3,9 @@ from datetime import date, datetime, timedelta
3
 
4
  import joblib
5
  import pandas as pd
 
6
  from dotenv import load_dotenv
7
  from huggingface_hub import hf_hub_download, login
8
-
9
  from src.data_api_calls import (
10
  get_combined_data,
11
  update_pollution_data,
@@ -17,26 +17,65 @@ load_dotenv()
17
  login(token=os.getenv("HUGGINGFACE_DOWNLOAD_TOKEN"))
18
 
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  def load_model(particle):
21
  repo_id = f"elisaklunder/Utrecht-{particle}-Forecasting-Model"
22
  if particle == "O3":
23
  file_name = "O3_svr_model.pkl"
24
- elif particle == "NO2":
25
- file_name = "NO2_svr_model.pkl"
 
 
26
 
27
- model_path = hf_hub_download(repo_id=repo_id, filename=file_name)
28
- model = joblib.load(model_path)
29
  return model
30
 
31
 
32
  def run_model(particle, data):
33
  input_data = create_features(data=data, target_particle=particle)
34
  model = load_model(particle)
35
- prediction = model.predict(input_data)
36
 
37
- repo_id = f"elisaklunder/Utrecht-{particle}-Forecasting-Model"
38
- file_name = f"target_scaler_{particle}.joblib"
39
- path = hf_hub_download(repo_id=repo_id, filename=file_name)
 
 
 
 
 
 
 
 
 
 
40
  target_scaler = joblib.load(path)
41
  prediction = target_scaler.inverse_transform(prediction)
42
 
 
3
 
4
  import joblib
5
  import pandas as pd
6
+ import torch
7
  from dotenv import load_dotenv
8
  from huggingface_hub import hf_hub_download, login
 
9
  from src.data_api_calls import (
10
  get_combined_data,
11
  update_pollution_data,
 
17
  login(token=os.getenv("HUGGINGFACE_DOWNLOAD_TOKEN"))
18
 
19
 
20
+ def load_nn():
21
+ import torch.nn as nn
22
+ from huggingface_hub import PyTorchModelHubMixin
23
+
24
+ class AirPollutionNet(nn.Module, PyTorchModelHubMixin):
25
+ def __init__(self, input_size, layers, dropout_rate):
26
+ super(AirPollutionNet, self).__init__()
27
+ self.layers_list = nn.ModuleList()
28
+ in_features = input_size
29
+
30
+ for units in layers:
31
+ self.layers_list.append(nn.Linear(in_features, units))
32
+ self.layers_list.append(nn.ReLU())
33
+ self.layers_list.append(nn.Dropout(p=dropout_rate))
34
+ in_features = units
35
+
36
+ self.output = nn.Linear(in_features, 3) # Output size is 3 for next 3 days
37
+
38
+ def forward(self, x):
39
+ for layer in self.layers_list:
40
+ x = layer(x)
41
+ x = self.output(x)
42
+ return x
43
+
44
+ model = AirPollutionNet.from_pretrained(
45
+ "akseljoonas/Utrecht_pollution_forecasting_NO2"
46
+ )
47
+ return model
48
+
49
+
50
  def load_model(particle):
51
  repo_id = f"elisaklunder/Utrecht-{particle}-Forecasting-Model"
52
  if particle == "O3":
53
  file_name = "O3_svr_model.pkl"
54
+ model_path = hf_hub_download(repo_id=repo_id, filename=file_name)
55
+ model = joblib.load(model_path)
56
+ else:
57
+ model = load_nn()
58
 
 
 
59
  return model
60
 
61
 
62
  def run_model(particle, data):
63
  input_data = create_features(data=data, target_particle=particle)
64
  model = load_model(particle)
 
65
 
66
+ if particle == "NO2":
67
+ with torch.no_grad():
68
+ prediction = model(torch.tensor(input_data.values, dtype=torch.float32))
69
+ repo_id = "akseljoonas/Utrecht_pollution_forecasting_NO2"
70
+ file_name = "target_scaler_NO2.joblib"
71
+ path = hf_hub_download(repo_id=repo_id, filename=file_name)
72
+ else:
73
+ prediction = model.predict(input_data)
74
+
75
+ repo_id = f"elisaklunder/Utrecht-{particle}-Forecasting-Model"
76
+ file_name = f"target_scaler_{particle}.joblib"
77
+ path = hf_hub_download(repo_id=repo_id, filename=file_name)
78
+
79
  target_scaler = joblib.load(path)
80
  prediction = target_scaler.inverse_transform(prediction)
81
 
weather_data.csv CHANGED
@@ -13,3 +13,4 @@ date,temp,humidity,precip,windspeed,sealevelpressure,visibility,solarradiation
13
  2024-10-28,12.4,91.8,1.1,31.7,1021.8,12.8,27.3
14
  2024-10-29,13.8,95.9,0.2,20.5,1023.1,8.1,16.0
15
  2024-10-30,12.7,92.9,0.6,9.4,1027.5,12.5,32.8
 
 
13
  2024-10-28,12.4,91.8,1.1,31.7,1021.8,12.8,27.3
14
  2024-10-29,13.8,95.9,0.2,20.5,1023.1,8.1,16.0
15
  2024-10-30,12.7,92.9,0.6,9.4,1027.5,12.5,32.8
16
+ 2024-10-31,12.5,89.9,0.0,11.2,1027.1,17.1,70.6