|
| 1 | +import streamlit as st |
| 2 | +import numpy as np |
| 3 | +import pickle |
| 4 | + |
| 5 | +# Load your pre-trained RandomForestRegressor model |
| 6 | +with open("random_forest_model.pkl", "rb") as file: |
| 7 | + model = pickle.load(file) |
| 8 | + |
| 9 | +# Set the title of the app |
| 10 | +st.title("Predicting Temperature in London") |
| 11 | + |
| 12 | +# header and description |
| 13 | +st.header("Predict Weather Conditions Based on Various Features") |
| 14 | + |
| 15 | +# link to the GitHub repository |
| 16 | +st.markdown("[GitHub Repo](https://github.com/Netcodez/Climate-Prediction-Pipeline)") |
| 17 | + |
| 18 | +st.write( |
| 19 | + """ |
| 20 | +This application uses a Random Forest Regression model to predict the mean temperature in London. |
| 21 | +Please enter the required features below to get a prediction. |
| 22 | +""" |
| 23 | +) |
| 24 | +feature_names = [ |
| 25 | + "Cloud Cover (oktas)", |
| 26 | + "Sunshine (hrs)", |
| 27 | + "Global Radiation (W/m²)", |
| 28 | + "Max Temp (°C)", |
| 29 | + "Min Temp (°C)", |
| 30 | + "Precipitation (mm)", |
| 31 | + "Pressure (Pa)", |
| 32 | + "Snow Depth (cm)", |
| 33 | + "Month", |
| 34 | +] |
| 35 | + |
| 36 | +# feature names with units of measurement and short descriptions |
| 37 | +feature_info = { |
| 38 | + "Cloud Cover (oktas)": { |
| 39 | + "range": (0.0, 9.0), |
| 40 | + "description": "Measurement of cloud cover in oktas", |
| 41 | + }, |
| 42 | + "Sunshine (hrs)": { |
| 43 | + "range": (0.0, 24.0), |
| 44 | + "description": "Measurement of sunshine in hours per day", |
| 45 | + }, |
| 46 | + "Global Radiation (W/m²)": { |
| 47 | + "range": (0.0, 500.0), |
| 48 | + "description": "Measurement of global radiation in Watt per " "square meter", |
| 49 | + }, |
| 50 | + "Max Temp (°C)": { |
| 51 | + "range": (-10.0, 40.0), |
| 52 | + "description": "Maximum temperature recorded in degrees Celsius", |
| 53 | + }, |
| 54 | + "Min Temp (°C)": { |
| 55 | + "range": (-10.0, 40.0), |
| 56 | + "description": "Minimum temperature recorded in degrees Celsius", |
| 57 | + }, |
| 58 | + "Precipitation (mm)": { |
| 59 | + "range": (0.0, 100.0), |
| 60 | + "description": "Measurement of precipitation in millimeters", |
| 61 | + }, |
| 62 | + "Pressure (Pa)": { |
| 63 | + "range": (90000.0, 110000.0), |
| 64 | + "description": "Measurement of pressure in Pascals", |
| 65 | + }, |
| 66 | + "Snow Depth (cm)": { |
| 67 | + "range": (0.0, 50.0), |
| 68 | + "description": "Measurement of snow depth in centimeters", |
| 69 | + }, |
| 70 | + "Month": {"range": (1, 12), "description": "Month of observation"}, |
| 71 | +} |
| 72 | + |
| 73 | +feature_values = [] |
| 74 | +for feature_name, info in feature_info.items(): |
| 75 | + min_val, max_val = info["range"] |
| 76 | + label = f"{feature_name}: {info['description']}" |
| 77 | + feature_values.append(st.slider(label, min_val, max_val, min_val)) |
| 78 | + |
| 79 | + |
| 80 | +# Prediction button |
| 81 | +if st.button("Predict"): |
| 82 | + input_data = np.array(feature_values).reshape(1, -1) |
| 83 | + prediction = model.predict(input_data) |
| 84 | + st.write(f"Mean Temperature in London is predicted to be {prediction[0]}°C") |
0 commit comments