import streamlit as st import numpy as np import pandas as pd import pickle from sklearn.linear_model import LinearRegression import warnings # Ignore InconsistentVersionWarning from scikit-learn warnings.filterwarnings("ignore", category=UserWarning, message=".*InconsistentVersionWarning.*") # Example data for training - include 'year_built' as a feature X_train = np.array([[1000, 3, 2, 1, 2000], [1500, 4, 3, 2, 1995], [2000, 3, 2, 2, 2010]]) # Include year_built y_train = np.array([300000, 400000, 500000]) # Example target data # Train the model with the example data model = LinearRegression() model.fit(X_train, y_train) # Save the model with the current version of scikit-learn (after training) with open("elite27_new.pkl", "wb") as f: pickle.dump(model, f) # Title for the app st.title("🏡 House Price Prediction App") # User input fields (including 'year_built') square_feet = st.number_input("Enter Square Feet:", min_value=500, max_value=10000) bedrooms = st.number_input("Enter Number of Bedrooms:", min_value=1, max_value=10) bathrooms = st.number_input("Enter Number of Bathrooms:", min_value=1, max_value=10) neighborhood = st.selectbox("Select Neighborhood: 0:Rural, 1:Semi Urban, 2:Urban", [0, 1, 2]) year_built = st.number_input("Enter Year Built:", min_value=1900, max_value=2025) # Define feature names (with 'YearBuilt') feature_names = ['SquareFeet', 'Bedrooms', 'Bathrooms', 'Neighborhood', 'YearBuilt'] # Predict price when the button is clicked if st.button("Predict Price 💰"): # Reshape user input into a 2D array (including 'year_built') user_data = np.array([[square_feet, bedrooms, bathrooms, neighborhood, year_built]]) # Convert user data into a DataFrame and set proper column names user_data_df = pd.DataFrame(user_data, columns=feature_names) # Predict price prediction = model.predict(user_data_df) # Display result st.success(f"🏠 Estimated House Price: ${prediction[0]:,.2f}")