Modelli di predizione giornaliera della pioggia basato su dati meteorologici storici.
I modelli combinano preprocessing (come imputing, scaling, encoding...) per prevedere se il giorno successivo ci sarà pioggia significativa (>0.6 mm) o nulla/minima (<0.6 mm).
1from huggingface_hub import hf_hub_download
2import joblib
3import pandas as pd
4
5# Scarica il modello dal repo Hugging Face
6model_path = hf_hub_download(repo_id="freyflyy/previsione-meteo-udine-modello", filename="model_v1.pkl") # modello base (v1)
7model_dict = joblib.load(model_path)
8
9imputer = model_dict["modello_imputer"]
10encoder = model_dict["modello_encoder"]
11model = model_dict["modello_predittivo"]
12
13# Esempio input
14input_dict = {
15 "Anno": 2025,
16 "Mese": "Ago",
17 "PosizioneMese": "Meta",
18 "DirVentoMax": "SO",
19 "TempMin [°C]": 16.3,
20 "TempMed [°C]": 23.1,
21 "TempMax [°C]": 28.1,
22 "UmiditaMed [%]": 69,
23 "UmiditaMax [%]": 91,
24 "VentoMed [km/h]": 5,
25 "VentoMax [km/h]": 19,
26 "Radiazione [KJ/m2]": 25998,
27 "Pressione [Pa]": 100770,
28 "mmPioggia": 0
29}
30
31df_input = pd.DataFrame([input_dict])
32
33# Preprocessing
34numerical_cols = df_input.select_dtypes(include=[float, int]).columns.tolist()
35categorical_cols = df_input.select_dtypes(include=["object"]).columns.tolist()
36
37df_input[numerical_cols] = imputer.transform(df_input[numerical_cols])
38encoded = encoder.transform(df_input[categorical_cols]).toarray()
39encoded_df = pd.DataFrame(encoded, columns=encoder.get_feature_names_out(categorical_cols), index=df_input.index)
40
41df_input_final = pd.concat([df_input.drop(columns=categorical_cols), encoded_df], axis=1)
42
43# Predizione
44pred = model.predict(df_input_final)[0]
45print("Predizione pioggia:", pred)
1from huggingface_hub import hf_hub_download
2import joblib
3import pandas as pd
4
5# Scarica il modello dal repo Hugging Face
6model_path = hf_hub_download(repo_id="freyflyy/previsione-meteo-udine-modello", filename="model_v2.pkl") # modello aggiornato (v2)
7model_dict = joblib.load(model_path)
8
9imputer = model_dict["modello_imputer"]
10encoder = model_dict["modello_encoder"]
11model = model_dict["modello_predittivo"]
12
13# Esempio input
14input_dict = {
15 "Anno": 2025,
16 "Mese": "Ago",
17 "PosizioneMese": "Meta",
18 "TempMin_C_": 16.3,
19 "TempMed_C_": 23.1,
20 "TempMax_C_": 28.1,
21 "UmiditaMed_": 69,
22 "UmiditaMax_": 91,
23 "VentoMed_km_h_": 5,
24 "VentoMax_km_h_": 19,
25 "DirVentoMax": "SO",
26 "Radiazione_KJ_m2_": 25998,
27 "Pressione_Pa_": 100770,
28 "mmPioggia": 0,
29 # Lag 1
30 "Anno_lag_1": 2025,
31 "Mese_lag_1": "Lug",
32 "PosizioneMese_lag_1": "Fine",
33 "TempMin_C__lag_1": 15.8,
34 "TempMed_C__lag_1": 22.5,
35 "TempMax_C__lag_1": 27.4,
36 "UmiditaMed__lag_1": 71,
37 "UmiditaMax__lag_1": 90,
38 "VentoMed_km_h__lag_1": 6,
39 "VentoMax_km_h__lag_1": 21,
40 "DirVentoMax_lag_1": "O",
41 "Radiazione_KJ_m2__lag_1": 25200,
42 "Pressione_Pa__lag_1": 100820,
43 "mmPioggia_lag_1": 1
44}
45
46
47df_input = pd.DataFrame([input_dict])
48
49# Preprocessing
50numerical_cols = df_input.select_dtypes(include=[float, int]).columns.tolist()
51categorical_cols = df_input.select_dtypes(include=["object"]).columns.tolist()
52
53df_input[numerical_cols] = imputer.transform(df_input[numerical_cols])
54encoded = encoder.transform(df_input[categorical_cols]).toarray()
55encoded_df = pd.DataFrame(encoded, columns=encoder.get_feature_names_out(categorical_cols), index=df_input.index)
56
57df_input_final = pd.concat([df_input.drop(columns=categorical_cols), encoded_df], axis=1)
58
59# Predizione
60preds_dict = {0:"Nulla o Minima", 1:"Presente"}
61pred = model.predict(df_input_final)[0]
62pred = preds_dict[pred]
63print("Predizione pioggia:", pred)
Se mancano dati per la giornata odierna, non lasciare il campo vuoto. Invece, usare quelli del giorno prima o i più recenti
I dati meteorologici possono essere prelevati dal sito dell'
Arpa FVG