File size: 1,837 Bytes
461452c
b8f3b36
 
 
 
 
 
461452c
b8f3b36
7d835f6
b8f3b36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}")