dvj4 commited on
Commit
b8f3b36
·
1 Parent(s): 3a6b096

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -2
app.py CHANGED
@@ -1,4 +1,50 @@
1
  import streamlit as st
 
 
 
 
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import xgboost as xgb
5
+ from sklearn.metrics import mean_squared_error
6
+ from sklearn.model_selection import train_test_split
7
+ import optuna
8
 
9
+ # Load the data
10
+ path = "train.csv"
11
+ data = pd.read_csv(path)
12
+
13
+ # Get features
14
+ y = data['SalePrice']
15
+ X = data[["LotArea","OverallQual", "OverallCond", "YearBuilt","TotRmsAbvGrd","GarageArea"]]
16
+
17
+ # Split the data
18
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
19
+
20
+ # Load the XGBoost model
21
+ model = xgb.XGBRegressor(objective ='reg:squarederror',
22
+ colsample_bytree = 1,
23
+ eta=0.3,
24
+ learning_rate = 0.01,
25
+ max_depth = 5,
26
+ alpha = 10,
27
+ n_estimators = 500)
28
+ model.fit(X_train, y_train)
29
+ # Create a sidebar with sliders for each feature
30
+ sidebar = st.sidebar
31
+ sidebar.title("Input Features")
32
+ lot_area = sidebar.slider("Lot Area", 1300, 215245, 50000)
33
+ overall_qual = sidebar.slider("Overall Quality", 1, 10, 5)
34
+ overall_cond = sidebar.slider("Overall Condition", 1, 10, 5)
35
+ year_built = sidebar.slider("Year Built", 1872, 2010, 1950)
36
+ tot_rooms_above_grade = sidebar.slider("Total Rooms Above Grade", 2, 14, 7)
37
+ garage_area = sidebar.slider("Garage Area", 0, 1418, 500)
38
+ # Create a Pandas DataFrame with the user's input
39
+ input_df = pd.DataFrame({
40
+ "LotArea": [lot_area],
41
+ "OverallQual": [overall_qual],
42
+ "OverallCond": [overall_cond],
43
+ "YearBuilt": [year_built],
44
+ "TotRmsAbvGrd": [tot_rooms_above_grade],
45
+ "GarageArea": [garage_area]
46
+ })
47
+ # Use the XGBoost model to predict the house price range for the user's input
48
+ prediction = model.predict(input_df)
49
+ # Display the predicted house price range to the user
50
+ st.write(f"The estimated house price range is ${prediction[0]:,.2f}")