import streamlit as st import joblib import numpy as np # Load models linear_model = joblib.load("linear_regression_model.pkl") decision_tree_model = joblib.load("decision_tree_regression_model.pkl") random_forest_model = joblib.load("random_forest_regress_model.pkl") app, model_eval = st.tabs(["Application", "Model Evaluation"]) with app: # Model selection (exclusive to this tab) st.sidebar.title("Select Model") model_choice = st.sidebar.radio("Choose a model:", ("Linear Regression", "Decision Tree Regression", "Random Forest Regression")) if model_choice == "Linear Regression": model = linear_model elif model_choice == "Decision Tree Regression": model = decision_tree_model else: model = random_forest_model # User inputs st.title("House Price Prediction") area = st.number_input("Area (sq ft)", min_value=100, max_value=10000, step=10) bedrooms = st.slider("Bedrooms", 1, 5, 3) bathrooms = st.slider("Bathrooms", 1, 4, 2) floors = st.slider("Floors", 1, 3, 1) year_built = st.number_input("Year Built", min_value=1800, max_value=2025, step=1) location = st.radio("Location", ["Suburban", "Downtown", "Rural", "Urban"]) condition = st.radio("Condition", ["Poor", "Good", "Excellent", "Fair"]) garage = st.radio("Garage", ["No", "Yes"]) # Encode categorical inputs location_dict = {"Suburban": 0, "Downtown": 1, "Rural": 2, "Urban": 3} condition_dict = {"Poor": 0, "Fair": 1, "Good": 2, "Excellent": 3} garage_dict = {"No": 0, "Yes": 1} location_encoded = location_dict[location] condition_encoded = condition_dict[condition] garage_encoded = garage_dict[garage] # Prediction button if st.button("Predict Price"): features = np.array([[area, bedrooms, bathrooms, floors, year_built, location_encoded, condition_encoded, garage_encoded]]) predicted_price = model.predict(features)[0] st.write(f"### Predicted House Price: ${predicted_price:,.2f}") with model_eval: st.title("Model Evaluation") st.subheader("Decision Tree Regression") st.image("DTR_metrics.png", caption="Decision Tree Regression Metrics") st.image("evalMetric_DTR.png", caption="Decision Tree Regression - Actual vs Predicted") st.subheader("Linear Regression") st.image("LR_metrics.png", caption="Linear Regression Metrics") st.image("evalMetric_LR.png", caption="Linear Regression - Actual vs Predicted") st.subheader("Random Forest Regression") st.image("RFR_metrics.png", caption="Random Forest Regression Metrics") st.image("evalMetric_RFR.png", caption="Random Forest Regression - Actual vs Predicted")