File size: 2,245 Bytes
1ae03dd
 
 
 
227357c
a6e15b1
ba2ab2f
1ae03dd
60999f9
1ae03dd
a6e15b1
60999f9
 
ef98bc7
 
ba2ab2f
 
a6e15b1
1ae03dd
a6e15b1
 
 
1ae03dd
 
 
 
 
 
a6e15b1
 
1ae03dd
 
 
 
a6e15b1
1ae03dd
a6e15b1
1ae03dd
a6e15b1
1ae03dd
 
 
 
 
a6e15b1
 
1ae03dd
a6e15b1
60999f9
1ae03dd
a6e15b1
1ae03dd
 
227357c
a6e15b1
 
1ae03dd
a6e15b1
1ae03dd
a6e15b1
 
60999f9
1ae03dd
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
import streamlit as st
import hopsworks
import joblib
import pandas as pd
import datetime
from functions import get_weather_data_weekly, data_encoder, get_aplevel
from PIL import Image


def fancy_header(text, font_size=24):
    res = f'<p style="color:#ff5f27; font-size: {font_size}px;text-align:center">{text}</p>'
    st.markdown(res, unsafe_allow_html=True)

st.set_page_config(layout="wide")
st.title('Air Quality Prediction Project for Vienna! 🌩')
vienna_image = Image.open('vienna.jpg')
st.image(vienna_image, use_column_width='auto')
st.write(36 * "-")

st.markdown("# This is a final project in the course ID2223 Scalable Machine Learning and Deep Learning :computer:")
st.markdown("My task was to predict the Air Quality Index (AQI) for one city (I choose Vienna) based on different weather data (pressure, snow-and cloud-coverage, temperature, etc.).")
st.markdown("For the full list of weather data, please click [here][https://visualcrossing.com/resources/documentation/weather-api/timeline-weather-api]")
fancy_header('\n Connecting to Hopsworks Feature Store...')

project = hopsworks.login()

st.write("Successfully connected!✔️")

st.write(36 * "-")
fancy_header('\n Collecting the weather data from Vienna...')

today = datetime.date.today()
city = "vienna"
weekly_data = get_weather_data_weekly(city, today)
st.write("Successfully collected!✔️")

st.write(36 * "-")

fancy_header("Loading the fitted XGBoost model...")
mr = project.get_model_registry()
model = mr.get_best_model("aqi_model", "rmse", "min")
model_dir = model.download()
model = joblib.load(model_dir + "/aqi_model.pkl")

st.write("Succesfully loaded!✔️")
st.sidebar.write("-" * 36)

fancy_header("Making AQI pedictions for the next week..")

preds = model.predict(data_encoder(weekly_data)).astype(int)

poll_level = get_aplevel(preds.T.reshape(-1, 1))

next_week_datetime = [today + datetime.timedelta(days=d) for d in range(7)]

next_week_str = [f"{days.strftime('%Y-%m-%d')}, {days.strftime('%A')}" for days in next_week_datetime]

df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=next_week_str)

st.write("Here they are!")
st.dataframe(df.style.apply) # ref to function color_aq

st.button("Re-run")