Milestone-3 / app.py
dvj4's picture
Update app.py
7d835f6
raw
history blame
1.84 kB
import streamlit as st
import pandas as pd
import numpy as np
import xgboost as xgb
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
import optuna
# Load the data
path = "/Users/deepjetani/Desktop/train.csv"
data = pd.read_csv(path)
# Get features
y = data['SalePrice']
X = data[["LotArea","OverallQual", "OverallCond", "YearBuilt","TotRmsAbvGrd","GarageArea"]]
# Split the data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
# Load the XGBoost model
model = xgb.XGBRegressor(objective ='reg:squarederror',
colsample_bytree = 1,
eta=0.3,
learning_rate = 0.01,
max_depth = 5,
alpha = 10,
n_estimators = 500)
model.fit(X_train, y_train)
# Create a sidebar with sliders for each feature
sidebar = st.sidebar
sidebar.title("Input Features")
lot_area = sidebar.slider("Lot Area", 1300, 215245, 50000)
overall_qual = sidebar.slider("Overall Quality", 1, 10, 5)
overall_cond = sidebar.slider("Overall Condition", 1, 10, 5)
year_built = sidebar.slider("Year Built", 1872, 2010, 1950)
tot_rooms_above_grade = sidebar.slider("Total Rooms Above Grade", 2, 14, 7)
garage_area = sidebar.slider("Garage Area", 0, 1418, 500)
# Create a Pandas DataFrame with the user's input
input_df = pd.DataFrame({
"LotArea": [lot_area],
"OverallQual": [overall_qual],
"OverallCond": [overall_cond],
"YearBuilt": [year_built],
"TotRmsAbvGrd": [tot_rooms_above_grade],
"GarageArea": [garage_area]
})
# Use the XGBoost model to predict the house price range for the user's input
prediction = model.predict(input_df)
# Display the predicted house price range to the user
st.write(f"The estimated house price range is ${prediction[0]:,.2f}")