File size: 3,923 Bytes
034574b
 
4d482a6
034574b
 
 
 
 
4d482a6
034574b
 
 
4d482a6
 
 
 
 
 
 
 
 
 
 
 
 
 
d92e33e
4d482a6
 
d92e33e
 
4d482a6
034574b
4d482a6
d92e33e
4d482a6
 
d92e33e
034574b
d92e33e
 
034574b
4d482a6
 
d92e33e
034574b
d92e33e
 
4d482a6
d92e33e
4d482a6
 
 
d92e33e
 
4d482a6
 
bdb2363
d92e33e
 
4d482a6
 
 
 
 
 
 
 
 
 
 
d92e33e
4d482a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d92e33e
4d482a6
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import streamlit as st
import pandas as pd
import joblib  

# MAPPING THE CLASSES
weather_mapping = {"rain": 0, "sun": 1, "fog": 2, "drizzle": 3, "snow": 4}
reverse_mapping = {v: k for k, v in weather_mapping.items()}  # Reverse mapping

# FEATURE COLUMNS
feature_columns = ["precipitation", "temp_max", "temp_min", "wind"]

# STREAMLIT UI
st.sidebar.title("🔍 Select Model")
model_choice = st.sidebar.radio("Choose a model:", 
                                ["Decision Tree (DTC)", "K-Nearest Neighbors (KNN)", "Random Forest (RFC)"])

# Load the chosen model
model_filename = {
    "Decision Tree (DTC)": "DTCweather_model.pkl",
    "K-Nearest Neighbors (KNN)": "KNNweather_model.pkl",
    "Random Forest (RFC)": "RFCweather_model.pkl"
}

model = joblib.load(model_filename[model_choice])

# STREAMLIT TABS
app, model_eval = st.tabs(["Application", "Model Evaluation"])

# STREAMLIT APP - TAB 1
with app:
    st.title("🌦️ Weather Prediction App")
    st.write(f"Using **{model_choice}**, enter weather conditions, and the model will predict the weather category!")

    # User Inputs
    precipitation = st.number_input("Precipitation (mm)", min_value=0.0, max_value=100.0, step=0.1)
    temp_max = st.number_input("Max Temperature (°C)", min_value=-20.0, max_value=50.0, step=0.1)
    temp_min = st.number_input("Min Temperature (°C)", min_value=-20.0, max_value=50.0, step=0.1)
    wind = st.number_input("Wind Speed (km/h)", min_value=0.0, max_value=100.0, step=0.1)

    if st.button("Predict Weather"):
        input_data = pd.DataFrame([[precipitation, temp_max, temp_min, wind]], columns=feature_columns)

        # Predict
        prediction_num = model.predict(input_data)[0]
        prediction_label = reverse_mapping.get(prediction_num, "Unknown")

        st.success(f"🌤️ Predicted Weather: **{prediction_label.capitalize()}**")

# MODEL EVALUATION - TAB 2
with model_eval:
    st.header("📊 Model Evaluation")
    st.write("The Weather Prediction models were trained to classify weather types based on conditions. The dataset was sourced from Kaggle.")
    st.write("Dataset by **ANANTH R**. [Link to dataset](https://www.kaggle.com/datasets/ananthr1/weather-prediction)")

    # CORRELATION MATRIX
    st.subheader("📌 Correlation Matrix")
    st.write("This matrix shows the relationships between features.")
    st.image("correlation_matrix.png")

    # WEATHER PREDICTION
    st.subheader("📌 Weather Prediction Results")
    st.write("Comparison of actual vs predicted weather conditions.")

    st.header("Decision Tree Classifier Weather Predictions")
    st.image("DTCweather_predictions.png")

    st.header("K Nearest Neighbor Weather Predictions")
    st.image("KNNweather_predictions.png")

    st.header("Random Forest Classifier Weather Predictions")
    st.image("RFCweather_predictions.png")

    # EVALUATION METRICS
    st.subheader("📌 Evaluation Metrics")
    st.write("Accuracy, F1 score, and the classification report of the models.")
    
    st.header("Decision Tree Classifier Evaluation Metrics")
    st.write("The image below represents the **Accuracy, F1 score, and classification report** of the Decision Tree Classifier model.")
    st.image("DTCclassification_report.png")
    
    st.header("K Nearest Neighbor Evaluation Metrics")
    st.write("The image below represents the **Accuracy, F1 score, and classification report** of the K Nearest Neighbor model.")
    st.image("KNNclassification_report.png")
    
    st.header("Random Forest Classifier Metrics")
    st.write("The image below represents the **Accuracy, F1 score, and classification report** of the Random Forest Classifier model.")
    st.image("RFCclassification_report.png")

    st.header("Comparison")
    st.write("Based on the evaluation metrics, we can assume that out of the three classification algorithms chosen, Ramdom Forest Classifier performs the best using this dataset")