CristopherWVSU's picture
added more models
4d482a6
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")